declare @SQL nvarchar(4000);
set @SQL=' select @TotalRecord=COUNT(*) from Company '
declare @TotalRecord int;
EXECUTE sp_executesql @SQL, '@TotalRecord int out ', @TotalRecord OUTPUT;
select @TotalRecord;
第4句中,在 '@TotalRecord int out '之前加上N,代码如下:
EXECUTE sp_executesql @SQL, N'@TotalRecord int out ', @TotalRecord OUTPUT;
set @SQL=' select @TotalRecord=COUNT(*) from Company '
declare @TotalRecord int;
这个吧,你的@TotalRecord 声明在下面,上面怎么就用@TotalRecord 了呢。应该是先声明后使用吧。
1 CREATE PROCEDURE test
2 @recordcount int output
3 As
4 set nocount on
5 begin
6 declare @sql nvarchar(4000)
7
8 set @sql = ' select @TotalRecord=COUNT(*) from customers'
9 --print @sql
10 Exec sp_executesql @sql,N'@recordCount int out',@recordCount out
11 set nocount off
12 end
希望对你有用
我也是参考别的地方的
http://www.rosoo.net/a/201112/15446.html
嗯啊,@TotalRecord得先申明的
declare @SQL nvarchar(4000)
set @SQL=' select @TotalRecord=COUNT(*) from Company'
declare @TotalRecord int
EXECUTE sp_executesql @SQL, N'@TotalRecord int out ', @TotalRecord OUTPUT
select @TotalRecord
@SQL声明为nvarchar,则应加“N”如:N'@TotalRecord int out '