I am not able to get the INSERT portion of the below procedure to work. Any help would be appreciated....
#currTable varchar(100),
#ID int,
#short_Text varchar(250),
#brief_Descrip varchar(250) = Null,
#needsTranslation varchar(10) = Null,
#prev_LangString varchar(250) = Null,
#lang_String varchar(250) = Null,
#original_lang_String varchar(250) = Null,
#StringID_from_Master int,
#GUID varchar(250) = Null
AS
BEGIN
SET NOCOUNT ON;
DECLARE #submitDate1 DATETIME;
SET #submitDate1 = GETDATE()
SET #prev_LangString = #original_lang_String
DECLARE #sql NVARCHAR(MAX);
SELECT #sql = N' UPDATE ' + QUOTENAME(#currTable) + ' SET [lang_String] = ''' + REPLACE(#lang_String,'''','''''') + ''', [date_Changed] = ''' + convert(varchar(20), #submitDate1) + ''', [prev_LangString] = ''' + #prev_LangString + ''', [needsTranslation] = ''' + #needsTranslation + ''' WHERE ID = ' + RTRIM(#ID) + '; ';
EXEC sp_executesql #sql;
INSERT tblPendingDBUpdates
( stringMasterID,
databaseName,
databaseStringID,
englishText,
foreignLangText,
submitDate,
GUID
)
SELECT #StringID_from_Master,
Database_Name,
dbKeyID_ofStringName,
#short_Text,
#lang_String,
#submitDate1,
#GUID
FROM tblDBUsage
WHERE tblUniquetblStringsMaster_ID = #StringID_from_Master;
END
I tried this code block only and no luck it did not INSERT to tblPendingDBUpdates.... Noticed something weird about GUID as field name so changed it in table also...
AS
BEGIN
SET NOCOUNT ON;
DECLARE #submitDate1 DATETIME;
SET #submitDate1 = GETDATE()
-- SET #prev_LangString = #original_lang_String
DECLARE #sql NVARCHAR(MAX);
DECLARE #currTable varchar(100);
SET #currTable = 'tblLangenUS'
DECLARE #ID INT;
SET #ID = 2
DECLARE #short_Text varchar(250);
SET #short_Text = 'testing99'
DECLARE #StringID_from_Master INT;
SET #StringID_from_Master = 2
DECLARE #lang_String varchar(250);
SET #lang_String = 'testing9999'
DECLARE #GUID1 varchar(250);
SET #GUID1 = 'Null'
INSERT tblPendingDBUpdates
( stringMasterID,
databaseName,
databaseStringID,
englishText,
foreignLangText,
submitDate,
GUID1
)
SELECT #StringID_from_Master,
Database_Name,
dbKeyID_ofStringName,
#short_Text,
#lang_String,
#submitDate1,
#GUID1
FROM tblDBUsage
WHERE tblUniquetblStringsMaster_ID = #StringID_from_Master;
END
I don't really know what you need but here is a stored proc with your declarations
CREATE PROCEDURE TestProc
AS
BEGIN
SET NOCOUNT ON;
DECLARE #submitDate1 DATETIME
SET #submitDate1 = GETDATE()
DECLARE #sql NVARCHAR(MAX)
DECLARE #StringID_from_Master INT
SET #StringID_from_Master = 2
DECLARE #short_Text varchar(250)
SET #short_Text = 'testing99'
DECLARE #lang_String varchar(250)
SET #lang_String = 'testing9999'
DECLARE #GUID1 varchar(250)
SET #GUID1 = 'Null'
BEGIN
EXEC sp_executesql #sql
END
BEGIN
INSERT INTO tblPendingDBUpdates
(
stringMasterID,
databaseName,
databaseStringID,
englishText,
foreignLangText,
submitDate,
GUID1
)
SELECT
#StringID_from_Master,
Database_Name,
dbKeyID_ofStringName,
#short_Text,
#lang_String,
#submitDate1,
#GUID1
FROM tblDBUsage
WHERE tblUniquetblStringsMaster_ID = #StringID_from_Master
END
END
GO
Well as far I understand it ... change the SP code to below and try again ... most probably will work fine
CREATE PROCEDURE <SOME NAME>
AS
BEGIN
<ALL YOUR DECLARATION HERE>
BEGIN
EXEC sp_executesql #sql;
END
GO
BEGIN
INSERT INTO tblPendingDBUpdates
(stringMasterID,
databaseName,
databaseStringID,
englishText,
foreignLangText,
submitDate,
GUID1)
SELECT #StringID_from_Master,
Database_Name,
dbKeyID_ofStringName,
#short_Text,
#lang_String,
#submitDate1,
#GUID1
FROM tblDBUsage
WHERE tblUniquetblStringsMaster_ID = #StringID_from_Master;
END
END
GO
If your not getting an error message and inserting zero rows, than you select statement must not be returning anything.
what does this return?
select *
FROM tblDBUsage
WHERE tblUniquetblStringsMaster_ID = #StringID_from_Master
If you're first stored proc it didn't look like #StringID_from_Master ever got set. That could be your problem.
Related
I have a stored procedure with dynamic sql that I need to return an OBJECT_RESULT type. I am trying to build the complex type within visual studio through EF. The problem, I believe, is coming from the fact that the table is one of the parameters of the proc. So when EF tries to build the type and the table is null, I get the error that the selected stored proc returns no columns. I have tried setting FMTONLY off and specified the actual columns in the select statement. Any way I can achieve this? The proc:
SET FMTONLY OFF
GO
ALTER PROCEDURE [dbo].[GetFormFieldCDC2]
(
#formfieldId INT,
#C___operation INT,
#C___start_lsn binary(10),
#schemaname sysname,
#tablename sysname
)
AS
SET NOCOUNT ON;
--IF (OBJECT_ID(QUOTENAME(#schemaname) + '.' + QUOTENAME(#tablename)) IS NULL)
-- THROW 50000, 'Table not found', 0;
DECLARE #sql AS NVARCHAR(MAX) = '
SELECT [__$start_lsn]
,[__$end_lsn]
,[__$seqval]
,[__$operation]
,[__$update_mask]
,[ID]
,[LookupList]
,[LookupColumns]
,[LookupAdditionalColumns]
,[FormFieldsID]
,[DateAdded]
,[DateEdited]
,[CreatedBy]
,[EditedBy]
,[__$command_id]
FROM ' + QUOTENAME(#schemaname) + '.' + QUOTENAME(#tablename) + '
WHERE __$start_lsn = #C___start_lsn
AND __$operation = #C___operation
AND FormFieldsID = #formfieldId;
';
EXEC sp_executesql #SQL,
N' #formfieldId INT,
#C___operation INT,
#C___start_lsn binary(10)',
#formfieldId = #formfieldId,
#C___operation = #C___operation,
#C___start_lsn = #C___start_lsn;
Don't set FMTONLY off. That's an old hack that is no longer necessary. Instead, explicitly declare the shape of the resultset, using EXECUTE ... WITH RESULT SETS when you execute the dynamic SQL. Like this:
CREATE OR ALTER PROCEDURE [dbo].[GetFormFieldCDC2]
(
#formfieldId INT,
#C___operation INT,
#C___start_lsn binary(10),
#schemaname sysname,
#tablename sysname
)
AS
BEGIN
/*
declare #object_id int = object_id('GetFormFieldCDC2')
select * from sys.dm_exec_describe_first_result_set_for_object(#object_id,0)
*/
SET NOCOUNT ON;
--IF (OBJECT_ID(QUOTENAME(#schemaname) + '.' + QUOTENAME(#tablename)) IS NULL)
-- THROW 50000, 'Table not found', 0;
DECLARE #sql AS NVARCHAR(MAX) = '
SELECT [__$start_lsn]
,[__$end_lsn]
,[__$seqval]
,[__$operation]
,[__$update_mask]
,[ID]
,[LookupList]
,[LookupColumns]
,[LookupAdditionalColumns]
,[FormFieldsID]
,[DateAdded]
,[DateEdited]
,[CreatedBy]
,[EditedBy]
,[__$command_id]
FROM ' + QUOTENAME(#schemaname) + '.' + QUOTENAME(#tablename) + '
WHERE __$start_lsn = #C___start_lsn
AND __$operation = #C___operation
AND FormFieldsID = #formfieldId;
';
EXEC sp_executesql #SQL,
N' #formfieldId INT,
#C___operation INT,
#C___start_lsn binary(10)',
#formfieldId = #formfieldId,
#C___operation = #C___operation,
#C___start_lsn = #C___start_lsn
WITH RESULT SETS
(
(
[__$start_lsn] binary(10)
,[__$end_lsn] binary(10)
,[__$seqval] binary(10)
,[__$operation] int
,[__$update_mask] varbinary(128)
,[ID] int
,[LookupList] varchar(max)
,[LookupColumns] varchar(max)
,[LookupAdditionalColumns] varchar(max)
,[FormFieldsID] int
,[DateAdded] datetime
,[DateEdited] datetime
,[CreatedBy] varchar(200)
,[EditedBy] varchar(200)
,[__$command_id] int
)
);
END
Then
declare #object_id int = object_id('GetFormFieldCDC2')
select * from sys.dm_exec_describe_first_result_set_for_object(#object_id,0)
Will return the resultset metadata.
This is so strange! The following code is a t-sql.
BEGIN
DECLARE #cinfo VARBINARY(128) = CAST('aud:83/53784862/1' AS VARBINARY(128));
DECLARE #csinfo VARCHAR(128) = CAST(CONTEXT_INFO() AS VARCHAR(128));
SET #csinfo = '<root><value>' + REPLACE(RIGHT(#cinfo, LEN(#cinfo) - 4), '/', '</value><value>') + '</value></root>';
PRINT #csinfo
SET CONTEXT_INFO #cinfo;
DECLARE #sql VARCHAR(MAX) = '
DECLARE #cinfo VARCHAR(128) = CAST(CONTEXT_INFO() AS VARCHAR(128));
DECLARE #csinfo VARCHAR(512) = ''<root><value>'' + REPLACE(RIGHT(#cinfo, LEN(#cinfo) - 4), ''/'', ''</value><value>'') + ''</value></root>'';
PRINT #csinfo
'
EXEC(#sql)
END
This is the output:
<root><value>83</value><value>53784862</value><value>1</value></root>
<root><value>83</value><value>53784862</value><value>1
Why </value></root> is not appended!
I found the solution.
DECLARE #cinfo VARCHAR(128) = REPLACE(CAST(CAST(CONTEXT_INFO() AS VARCHAR(128)) COLLATE SQL_Latin1_General_CP1_CI_AS AS VARCHAR(128)), CHAR(0), '');
this will repair the string convert from CONTEXT_INFO().
I am calling a stored procedure called Searchprocedure. I get an error at line where I am calling it. I have not made any changes to the parameters passed in the procedure and it was called just fine with same calling statement earlier.
Exec SearchProcedure #firstname = 'Simran', #middlename = 'kaur', #lastname = 'Khurana', #City = 'Delhi'
What's wrong with the syntax that is gives the error that says:
Incorrect syntax near '='
Edit:
Statement where I did :
set #sql = 'declare ' + '#Temp'+ #colVar + ' int'
exec(#sql)
select #sql as 'SQLFORDECLARATIONS
outputs
declare #TempMiddleName int
yet when I try to set value in the variable gives error that it should be declared first.
The set statement results in :
select #TempMiddleName=dbo.[MatchMiddleName](MiddleNameFromUser,MiddleNameFromTable,0)
which is what is should be yet it not able to see the declared variable
The stored procedure is as follows:
create procedure SearchProcedure
(
#firstname nvarchar(20),
#middlename nvarchar(20) = null,
#lastname nvarchar(20),
#DOB Date = null,
#SSN nvarchar(30)= null,
#ZIP nvarchar(10)= null,
#StateOfResidence nvarchar(2)= null,
#City nvarchar(20)= null,
#StreetName nvarchar(20)= null,
#StreetType nvarchar(20)= null,
#BuildingNumber int= null,
#Aptnumber nvarchar(10)= null
)
As
DECLARE #sSQL NVARCHAR(2000), #Where NVARCHAR(1000) = ' '
declare #Percent int,
#FN nvarchar(20),
#MN nvarchar(20) = null,
#LN nvarchar(20),
#DateOfB Date = null,
#SSNumber nvarchar(30)= null,
#ZIPCode nvarchar(10)= null,
#StateOfRes nvarchar(2)= null,
#CityOfRes nvarchar(20)= null,
#StreetNameRes nvarchar(20)= null,
#StreetTypeRes nvarchar(20)= null,
#BuildingNumberRes int= null,
#AptnumberRes nvarchar(10)= null
set #Percent = 0
create table #results
(
firstname nvarchar(20) not null,
middlename nvarchar(20),
lastname nvarchar(20)not null,
PercentageMatch int not null,
DOB Date,
SSN nvarchar(30),
ZIP nvarchar(10),
[State] nvarchar(2),
City nvarchar(20),
StreetName nvarchar(20),
StreetType nvarchar(20),
BuildingNumber int,
Aptnumber nvarchar(10)
)
declare c Cursor local static Read_only
for
SELECT * from dbo.Patients where firstname = #firstname
open c
fetch next from c into #FN,
#MN,
#LN,
#DateOfB,
#SSNumber,
#ZIPCode,
#StateOfRes,
#CityOfRes,
#StreetNameRes,
#StreetTypeRes,
#BuildingNumberRes,
#AptnumberRes
while ##FETCH_STATUS = 0 BEGIN
/*set #Percent = dbo.[MatchLastName](#lastname, #LN, #Percent)
set #Percent = dbo.[MatchMiddleName](#middlename, #MN, #Percent)
set #Percent = dbo.[MatchCity](#City, #CityOfRes, #Percent)*/
Exec [dbo].[OutputProcedure] #lastname, #LN, #middlename, #MN,#City, #CityOfRes, #Percent output
Insert into #results values
(#FN,#MN,#LN,#Percent, #DateOfB,#SSNumber, #ZIPCode,#StateOfRes,#CityOfRes,#StreetNameRes,#StreetTypeRes,#BuildingNumberRes,#AptnumberRes)
fetch next from c into #FN,
#MN,
#LN,
#DateOfB,
#SSNumber,
#ZIPCode,
#StateOfRes,
#CityOfRes,
#StreetNameRes,
#StreetTypeRes,
#BuildingNumberRes,
#AptnumberRes
end
select * from #results order by PercentageMatch desc
IF OBJECT_ID('tempdb..#results') IS NOT NULL DROP TABLE #results
go
OutputProcedure code is as follows:
CREATE Procedure OutputProcedure
(
#LastNameFromUser nvarchar(20) = null,
#LastNameFromTable nvarchar(20),
#MiddleNameFromUser nvarchar(20) = null,
#MiddleNameFromTable nvarchar(20) = null,
#CityFromUser nvarchar(20) = null,
#CityFromTable nvarchar(20) = null,
#Percentage int out
)
AS
BEGIN
select 'OUTPUTPROCEDURECALLED'
declare #maxvalue int
DECLARE #variableTable TABLE (
idx int identity(1,1),
matchvalue nvarchar(15))
INSERT INTO #variableTable(matchvalue) values ('MiddleName')
INSERT INTO #variableTable(matchvalue) values ('LastName')
INSERT INTO #variableTable(matchvalue) values ('City')
SELECT * FROM #variableTable
DECLARE #counter int
declare #sql nvarchar(100)
declare #sql2 nvarchar(25), #finalResult nvarchar(100)
declare #sql3 nvarchar(300), #sql4 nvarchar(15), #tempresultStore nvarchar(20), #temp int, #temp2 int, #average int
SET #counter = 1
SELECT #maxvalue = (SELECT MAX(idx) FROM #variableTable)
select #maxvalue as 'MAXVALUE'
WHILE(#counter <= #maxvalue)
BEGIN
DECLARE #colVar nvarchar(15)
SELECT #colVar = matchvalue FROM #variableTable WHERE idx = #counter
set #sql = 'declare ' + '#Temp'+ #colVar + ' int'
exec(#sql)
select #sql as 'SQLFORDECLARATIONS'
/*set #temp = CHARINDEX(' ',#sql)
select #temp as 'resultofcharindex'
set #temp2 = LEN(#sql) - (#temp)
SELECT #temp2 AS 'AFTERADDING1'
set #tempresultStore = right(#sql, #temp2)*/
set #tempresultStore = 'Temp'+#colVar
SELECT #tempresultStore AS 'FINALCUTPART'
set #sql3 = 'set ' + ' ' + #tempresultStore + '=' + 'dbo.[Match' + #colVar + '](' + #colVar + 'FromUser' + ',' + #colVar + 'FromTable' + ',' + '0)'
EXEC(#sql3)
select #sql3 as 'check sql query formed'
set #finalResult = #finalResult + #tempresultStore
select #finalResult as 'SUM'
SET #counter = #counter + 1
select #counter as 'COUNTERVALUE'
END
set #Percentage = #finalResult/#maxvalue
SELECT #Percentage AS 'FINALRESULT'
RETURN
END
--Setting variable in Dynamic SQL
DECLARE
#sql NVARCHAR(MAX),
#Name NVARCHAR(100)
SET #Name = '#B2E0EB1A'
SET #sql =
'
DECLARE #MyVar NVARCHAR(100)
SELECT TOP 1 #MyVar = name FROM sys.objects WHERE name LIKE ''%a''--Escaping single quote with double quote
PRINT #MyVar
'
EXEC(#sql)
SET #sql =
'
DECLARE #MyVar NVARCHAR(100)
SET #MyVar = '''+(SELECT TOP 1 name FROM sys.objects WHERE name LIKE '%a')+'''--Escaping single quote with double quote
PRINT #MyVar
'
EXEC(#sql)
SET #sql =
'
DECLARE #MyVar NVARCHAR(100)
SET #MyVar = '''+#Name+'''--Escaping single quote with double quote
PRINT #MyVar
'
EXEC(#sql)
SET #sql =
'
DECLARE #MyVar NVARCHAR(100)
SET #MyVar = ''#B2E0EB1A''--Escaping single quote with double quote
PRINT #MyVar
'
EXEC(#sql)
If you want to get output variable from your dynamic query you have to use sp_executesql procedure instead of EXEC()
Study this code
DECLARE #DynamicSQLOutput NVARCHAR(100)
DECLARE #SQL nvarchar(500);
DECLARE #ParmeterDefinition nvarchar(500);
--in this variabe you write the variables which you want to be declared in the dynamic sql without using the declare
SET #ParmeterDefinition = N'#FinalOutputResultInDynamicSQL NVARCHAR(100) OUTPUT';
--here you write your dynamic code
SELECT #SQL = N'SET #FinalOutputResultInDynamicSQL = ''test'' '
EXEC sp_executesql
#SQL, --Execute code
#ParmeterDefinition, -- Define Parameters
#FinalOutputResultInDynamicSQL = #DynamicSQLOutput OUTPUT --Get output
--Note that #FinalOutputResultInDynamicSQL is only defined in #ParmeterDefinition but not outside of the dynamic sql
PRINT #DynamicSQLOutput;
I think too many things wrong in your Dynamic sql. I found one
SET #sql3 = 'set ' + ' ' + #tempresultStore + ' = ' + 'dbo.[Match'
+ #colVar + '](' + #colVar + 'FromUser' + ',' + #colVar
+ 'FromTable' + ',' + '0)'
In the above code instead of Set use Select. Looks like you are selecting from a UDF. Try this
SET #sql3 = 'Select ' + ' ' + #tempresultStore + ' = ' + 'dbo.[Match'
+ #colVar + '](' + #colVar + 'FromUser' + ',' + #colVar
+ 'FromTable' + ',' + '0)'
Note : To debug Dynamic Sql before Exec #sql just use print #sql to check the syntax and other stuff in generated sql
I can't find any error and can run the exec without anerror message.
Edit: After I created the (now avialbe) output procedure and uncomment its call, I'm getting the error too...
Still investigating
Edit2:
In the Output procedure you have to use
set #sql = 'declare ' + '#Temp'+ #colVar + ' int' (# before Temp) and
set #sql3 = 'set ' + ' #' + #tempresultStore" (additional # after the 'set'.
Btw: you can exec more than one statement in Dynamic SQL so you could use f.e. exec (#sql + '; ' + #sql3);
i'm trying to make a txt file with a single command line output in it.
However for some reason it doesn't want to add the text and the test name into it..
Here's my code:
declare #command AS varchar(200)
declare #cmd AS varchar(200)
declare #input AS varchar(200)
declare #timeinput AS varchar(200)
declare #test AS varchar(1000)
declare #failureid as int
select #timeinput = (select time from inserted)
select #input = (select action from inserted)
select #failureid = (select failureId from inserted)
select #test = (select name from dbo.Alert where FailureId = #failureid)
if (#input = 'start')
BEGIN
set #command = ('EnableTest' + #test)
END
if (#input = 'stop')
BEGIN
set #command = ('DisableTest' + #test)
END
if (#input = 'pauze')
set #command = ('PauseTest' + #test + #timeinput)
END
SET #cmd = 'echo ' + #command + ' > F:\commandfolder\testing.HMS'
EXECUTE Master.dbo.xp_CmdShell #cmd
and the output in the HMS file is: DisableTest (with the testname missing)
The #test doesn't add into the file.
The data in my tables is correct as far as I know
Any ideas?
Thanks in advance & kind regards,
Dave
how about:
declare #command AS varchar(200)
declare #cmd AS varchar(200)
declare #input AS varchar(200)
declare #timeinput AS varchar(200)
declare #test AS varchar(1000)
declare #failureid as int
select #timeinput = (select time from inserted)
select #input = (select action from inserted)
select #failureid = (select failureId from inserted)
select #test = (select name from dbo.Alert where FailureId = #failureid)
if (#input = 'start')
BEGIN
set #failureid = (select failureId from inserted where action= #input)
set #test = (select name from dbo.Alert where FailureId = #failureid)
set #command = ('EnableTest' + #test)
END
if (#input = 'stop')
BEGIN
set #failureid = (select failureId from inserted where action= #input)
set #test = (select name from dbo.Alert where FailureId = #failureid)
set #command = ('DisableTest' + #test)
END
if (#input = 'pauze')
begin
set #failureid = (select failureId from inserted where action= #input)
set #test = (select name from dbo.Alert where FailureId = #failureid)
set #command = ('PauseTest' + #test + #timeinput)
END
SET #cmd = 'echo ' + #command + ' > F:\commandfolder\testing.HMS'
EXECUTE Master.dbo.xp_CmdShell #cmd
Basicaly, my guess is that you will have to set the Variable for every single case otherswise it remains the same.
It appears to be working now with no adjustments.
I don't know why it didn't, but the code is correct.
Using this SP I keep getting an error on the UPDATE statement indicating that I have conversion problem or something. But ID is an integer in all of my tables....
Conversion failed when converting the varchar value 'UPDATE tblLangenUS SET [lang_String] = ' - asdfgsdfg', [prev_LangString] = ' ', [needsTranslation] = 'false' WHERE [ID] = '' to data type int.
#currTable varchar(100),
#ID int,
#short_Text varchar(250),
#brief_Descrip varchar(250) = Null,
#needsTranslation varchar(10) = Null,
#prev_LangString varchar(250) = Null,
#lang_String varchar(250) = Null,
#original_lang_String varchar(250) = Null,
#StringID_from_Master varchar(250),
#GUID varchar(250) = Null
/*
*/
AS
SET NOCOUNT ON;
DECLARE #userTable AS VARCHAR(200);
SET #userTable = #currTable
DECLARE #submitDate1 DATETIME;
SET #submitDate1 = GETDATE()
SET #prev_LangString = #original_lang_String
SET #needsTranslation = 'false'
DECLARE #sql varchar(max)
-- Establish update to the language tabel of user and prepare to search DB for all strings that will need to be updated.
BEGIN
SET #sql = 'UPDATE ' + #currTable + ' SET [lang_String] = ''' + #lang_String + ''', [prev_LangString] = ''' + #prev_LangString + ''', [needsTranslation] = ''' + #needsTranslation + ''' WHERE [ID] = ''' + #ID + '''; '
EXEC #sql
#sql = ''
END
BEGIN
DECLARE usedIN_DBScursor CURSOR
FOR
SELECT tblUniquetblStringsMaster_ID, Database_Name, dbKeyID_ofStringName
FROM tblDBUsage
WHERE (tblUniquetblStringsMaster_ID = #StringID_from_Master );
-- Declare the variables to store the values returned by FETCH.
DECLARE #tblUniquetblStringsMaster_ID AS INT;
DECLARE #dbKEYID as INT;
DECLARE #dbName as varchar(100);
OPEN usedIN_DBScursor;
-- Perform the first fetch and store the values in variables.
-- Note: The variables are in the same order as the columns
-- in the SELECT statement.
FETCH NEXT FROM usedIN_DBScursor
INTO #tblUniquetblStringsMaster_ID, #dbName, #dbKEYID;
-- Check ##FETCH_STATUS to see if there are any more rows to fetch.
WHILE ##FETCH_STATUS = 0
BEGIN
-- Update pending strings table with translation.
BEGIN
INSERT INTO tblPendingDBUpdates
(stringMasterID, databaseName, databaseStringID, englishText, foreignLangText, submitDate, GUID)
VALUES (#StringID_from_Master, #dbName, #dbKEYID, #short_Text, #lang_String, #submitDate1, #GUID);
END
-- SET #sql = ''
-- This is executed as long as the previous fetch succeeds.
FETCH NEXT FROM usedIN_DBScursor
INTO #tblUniquetblStringsMaster_ID, #dbName, #dbKEYID;
END
CLOSE usedIN_DBScursor;
DEALLOCATE usedIN_DBScursor;
END
RETURN
If the ID is an int, you must CAST it to an nvarchar
SET #sql = 'UPDATE ' + #currTable + ' SET [lang_String] = ''' + #lang_String + ''', [prev_LangString] = ''' + #prev_LangString + ''', [needsTranslation] = ''' + #needsTranslation + ''' WHERE [ID] = ''' + CAST(#ID as nvarchar(10)) + '''; '
Otherwise, you are trying to add a string and an integer together, which won't work.
Notice this part:
' WHERE [ID] = ''' + CAST(#ID as nvarchar(10)) + '''
I think you must also change your EXEC syntax to:
EXEC(#sql)