I have a SQL CLR stored procedure dbo.Parallel_AddSql that takes a SQL query to execute as a string parameter.
It looks something like this :
exec dbo.Parallel_AddSql 'sql1',
'insert into test.dbo.table_1 values (1, ''test1'')'
I need to pass my SQL query as dynamic SQL statement to Parallel_AddSql procedure.
SQL statement that I need to pass is procedure execution statement with parameters i.e
Exec dbo.MatchLastName @LastNameFromUser = @LastName,
@checkbool = @checkbool
How do I pass this? As @lastName and @checkbool will be out of scope if I pass them as such in the string.
I tried using this :
set @SQL = 'Exec dbo.MatchFirstName @FirstNameFromUser =' + @firstname + ',
@checkbool = ' + cast(@checkbool as nvarchar(10))
exec dbo.Parallel_AddSql 'sql1', @SQL
However, I get this error :
Could not find stored procedure 'dbo.MatchFirstName'
dbo.MatchFirstName is there but dbo.Parallel_AddSql is not able to see it at all.
dbo.Parallel_AddSql is coming the library code given here
Edit : Unclosed quotation mark error :
set @SQL = 'Exec dbo.MatchFirstName @FirstNameFromUser =''' + @firstname
+ ''', @checkbool = ''' + cast(@checkbool as nvarchar(10))