I have a cursor which works fine but when it gets to this part of the script, it seems to still run the update even though the table doesn’t exists:
SET @sql = 'IF (EXISTS (SELECT * FROM ps_vars_' + @datasetid + '))
BEGIN
UPDATE ps_vars_' + @datasetid + '
SET programming_notes = replace(programming_notes, ''Some of the variables listed are source variables.'')
END';
EXEC SP_EXECUTESQL @sql
What am I missing? The #datasetid variable gets passed in correctly too.
1 Answer