sql server - Dynamic SQL gives "Incorrect Syntax Near '+'" -


i being extremely dumb here why simple dynamic query:

exec sp_executesql n'select id dbo.widgets id = ' + 1; 

give "incorrect syntax near '+'"

?

you can't formulate expression part of argument. , shouldn't concatenating way anyway (think sql injection) - you're using sp_executesql already, why not use proper parameter?

declare @id int, @sql nvarchar(max); set @id = 1; -- presumably come elsewhere  set @sql = n'select id dbo.widgets id = @id;'; exec sp_executesql @sql, n'@id int', @id; 

Comments

Popular posts from this blog

java.util.scanner - How to read and add only numbers to array from a text file -

rewrite - Trouble with Wordpress multiple custom querystrings -