sql server - MS SQL - Where are the syntax and scalar errors? -


i've been beating head on brick wall morning. simplified example of error(s) i've been receiving. using ssms.

declare @myid nvarchar(10) = '5' declare @sql nvarchar(2048) = 'select id applications a.id=@myid' execute sp_executesql @sql, @myid=@myid 

errors:

msg 102, level 15, state 1, line 1 incorrect syntax near '5'. msg 137, level 15, state 2, line 1 must declare scalar variable "@myid".

why getting syntax, , scalar errors? @myid defined, right?

sp_executesql needs receive definition of parameters, missing. so, in case, should use:

declare @myid nvarchar(10) = '5'; declare @sql nvarchar(2048) = 'select id applications a.id=@myid'; execute sp_executesql @sql, n'@myid nvarchar(10)', @myid=@myid; 

Comments

Popular posts from this blog

java - Static nested class instance -

c# - Bluetooth LE CanUpdate Characteristic property -

JavaScript - Replace variable from string in all occurrences -