Hi,
I am having problems setting the value of a variable in a SQL String
that I have to create dynamically in my procedure. The code that I
currently have is as follows:
set @sqlStatement=' Set @compare_string =' + '(Select ' +
@group_column_l ist_mod + ' from ' + @Tbl_Name + '_Sorted' + ' where
Identity_Column =' + ltrim(rtrim(str (@loop_counter) )) + ')'
exec(@sqlStatem ent)
The error message that I get is as follows:
Must declare the variable '@compare_strin g'.
Here @compare_string has already been declared in the procedure and I
don't have a problem using the variable anywhere else but this SQL
Statement (when called using the EXEC function).
I am not sure why SQL Server can't see the variable declared when used
in a string in conjunction with EXEC. Is this a syntax issue? Any help
on this issue would be greatly appreciated!
Thanks in advance.
I am having problems setting the value of a variable in a SQL String
that I have to create dynamically in my procedure. The code that I
currently have is as follows:
set @sqlStatement=' Set @compare_string =' + '(Select ' +
@group_column_l ist_mod + ' from ' + @Tbl_Name + '_Sorted' + ' where
Identity_Column =' + ltrim(rtrim(str (@loop_counter) )) + ')'
exec(@sqlStatem ent)
The error message that I get is as follows:
Must declare the variable '@compare_strin g'.
Here @compare_string has already been declared in the procedure and I
don't have a problem using the variable anywhere else but this SQL
Statement (when called using the EXEC function).
I am not sure why SQL Server can't see the variable declared when used
in a string in conjunction with EXEC. Is this a syntax issue? Any help
on this issue would be greatly appreciated!
Thanks in advance.
Comment