The "incorrect syntax near 'YN8888'" error is generated by the
EXEC (@sql) line.
It is not due to the
SET @PDSLINEID... line, but to the
SELECT... line immediately following it.
If you change that line as follows, all should be good:
SELECT @sql = 'SELECT ' + @colnm + ' FROM PDTABLE_FABISOS
WHERE CHKISODATA15 = ''' + @PDSLINEID + ''''
Here we are wrapping the
@PDSLINEID value in quotes, as it is a string.
You can help keep an eye out for these things when developing your code by putting in
before you try to execute the command - that'll show you if you're about to run the right thing or not.
May 08 '12 at 05:13 PM