I'm getting a MSG 102 error for the script below. I think it is something to do with the syntax around the end of the @SQL variable, in bold and underlined. I've tried braces and quotes but now getting frustrated....!
SET CONCAT_NULL_YIELDS_NULL OFF
SET @i = @i + 1
SET @SQL = 'UPDATE dbo.SFSOURCE SET csmerge = csmerge + CASE When'+' ' + @t + CAST(@i as VARCHAR(2))+' ' + 'IS null then null else' + '";"' + @t + CAST(@i as VARCHAR(2)) +' '+ 'END'
EXEC sp_executesql @SQL