I was reviewing a stored procedure where I found piece of code below. Looking at the code, my perception is that we are creating a variable named @QuestionInclude and passing its value in dynamic sql statement. But how this code is working?
This is something strage and new to me.
declare @QuestionInclude varchar(10)
select @sqln = 'select @QuestionInclude = 1 from ##Stg_Prelim'
exec sp_executesql @sqln,N'@QuestionInclude varchar(10) output',@QuestionInclude output
may be this will help you
http://msdn.microsoft.com/en-us/library/ms188001.aspx
procedure
sp_executesqlhave parameters@stmt, which is actual statement to run,@params– declaration of parameters, and then all parameters declared in@paramsIt’s also better to pass parameters by names