如何获取返回值?

smartyyp 2003-10-14 05:30:10
declare @str as varchar(8000)
declare @returnValue as integer
set @str='select count(id) from table'
set @str=@str+'where ...'
set @str=@str+'and ...'
set @returnValue=exec(@str)
如何用@returnValue获取exec执行sql中的返回字段值count(id)
我上面的方法是错误的,请高手指点!
...全文
59 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
Wally_wu 2003-10-14
  • 打赏
  • 举报
回复
declare @str as varchar(8000)
declare @returnValue as integer output
set @str='select count(id) from table'
set @str=@str+'where ...'
set @str=@str+'and ...'
set @returnValue=exec(@str)



declare @countid int
exec sp_executesql @countid output
yujohny 2003-10-14
  • 打赏
  • 举报
回复
来晚了,up
pengdali 2003-10-14
  • 打赏
  • 举报
回复
declare @str nvarchar(4000)
declare @returnValue as integer
set @str='select @a=count(id) from table'
set @str=@str+'where ...'
set @str=@str+'and ...'

exec sp_executesql @str,N'@a int output',@returnValue output

select @returnValue 结果

34,590

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server相关内容讨论专区
社区管理员
  • 基础类社区
  • 二月十六
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧