April 17, 2008 at 4:13 am
April 17, 2008 at 4:33 am
Use sp_executesql insead of EXECUTE. It allows you to pass variables in and out of dynamic SQL
books online has plenty examples
Gail Shaw
Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability
April 17, 2008 at 6:32 am
sp_executesql
DECLARE @SQLString nvarchar(500);
DECLARE @a int;
SET @SQLString = N'SELECT @OutVariable = bp_id from bug_posts where bp_bug=4648 ';
EXECUTE sp_executesql @SQLString, N'@OutVariable int OUTPUT', @OutVariable=@a OUTPUT;
PRINT @a
Gail Shaw
Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability
Viewing 5 posts - 1 through 4 (of 4 total)
You must be logged in to reply to this topic. Login to reply