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
Post a Comment