日期:2014-05-17  浏览次数:20384 次

存储过程带输出参数
存储过程中,我带输出参数
比如crete procedure asd
@pageSize int,--页大小
@pageIndex int,--页索引
@@tolPage int output,--总页数
@tolRecord int output,--总记录数
as
exec sp_executesql @sql,N'@toltemp int output',@tolRecord output

--获取总页数
set @tolPage=CEILING(@tolRecord*1.0/@pageSize) 
declare  @tolPage int,  @tolRecord int 
exec proc_GetNoteByCondition 5, 1,  @tolPage out ,@tolRecord out
我这样执行是有错~
消息 137,级别 15,状态 2,第 1 行
必须声明标量变量 "@tolPage"。
另外有个疑问,我可以在一个存储过程中使用两此exec sp_executesql么?
比如
exec sp_executesql @sql,N'@toltemp int output',@tolRecord output
exec sp_executesql @sql1,N'@toltemp int output',@tolRecord1 output 
11111111

------解决方案--------------------
set @tolPage=CEILING(@tolRecord*1.0/@pageSize) 
declare  @tolPage int,  @tolRecord int 
exec proc_GetNoteByCondition 5, 1,@tolPage,@tolRecord
------解决方案--------------------
消息 137,级别 15,状态 2,第 1 行
必须声明标量变量 "@tolPage"。
--> @@tolPage int output,--总页数
    参数声明有问题吧,应该是"@tolPage", 非"@@tolPage".

另外有个疑问,我可以在一个存储过程中使用两此exec sp_executesql么?
--> 可以.
------解决方案--------------------

exec sp_executesql @sql,N'@toltemp int output',@tolRecord output

--获取总页数
set @tolPage=CEILING(@tolRecord*1.0/@pageSize)   --这个之前有没有定义@tolPage的语句?
declare  @tolPage int,  @tolRecord int