SET @sql = 'Declare ChildTableMigrator CURSOR FOR select ['+@FieldName+'] , ['+@FieldName+'Alias] from [' + @SourceTable + '].[dbo].[Port] where [' + @SourceTable + '].[dbo].[Port].[' + @FieldName + '] IS NOT NULL AND [' + @SourceTable + '].[dbo].[Port].[' + @FieldName + '] !='''
PRINT @sql
exec sp_executesql @sql
Hi,
How to check NULL and EMPTY with a sql dynamic query ? , as per EMPTY check
@FieldName + '] !='''
it thorws the error
Unclosed quotation mark after the character string ”.
How to overcome this ?
You need to replace
with
Quotation marks need to be escaped when used inside a string. In your original statement, you escaped only one quotation mark resulting in a string with only one quotation mark.
But you could do even better by using parametrized sql