首页 > 代码库 > sp_executesql 两种写法

sp_executesql 两种写法

写法1:

AlTER PROCEDURE TryAgain@ReturnValue int output    ASdeclare @aa nvarchar(1000),        @ForumID int,        @count int,        @TotalRecords intBEGINset @ForumID =1    set @aa=Nselect  @ReturnValue=http://www.mamicode.com/count(1) from TC_BBS_Topics tc_bt where ForumID=+convert(varchar(10),@ForumID)EXEC sp_executesql @aa,N@ReturnValue int output ,@ReturnValue   outputEND

写法2:

AlTER PROCEDURE TryAgain@ReturnValue int output    ASdeclare @aa nvarchar(1000),        @ForumID int,        @count intBEGINset @ForumID =1    ;set @aa=Nselect  @count=count(1) from TC_BBS_Topics tc_bt where ForumID=@id;EXEC sp_executesql @aa,N@id int,@count int output ,@id = @ForumID, @count=@ReturnValue   output;END