加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > MsSql教程 > 正文

sql-server-2005 – 返回两个输出参数sp_executesql

发布时间:2020-12-12 08:44:08 所属栏目:MsSql教程 来源:网络整理
导读:我有动态查询我想从中获取两个输出参数我使用以下代码,但输出参数返回null declare @query nvarchar(max);declare @result int; declare @type intdeclare @mainVarcharLength int; set @query = 'select count(*),Type_Code from Customers WHERE Customers.
我有动态查询我想从中获取两个输出参数我使用以下代码,但输出参数返回null
declare @query nvarchar(max);
declare @result int; 
declare @type int
declare @mainVarcharLength int; 

set @query = 'select   count(*),Type_Code from Customers   WHERE Customers.Cust_Name =  ''CUSTOMER 99''  '
set @query = @query + '  and Cus_Is_Active = 1  Group BY   Type_Code';
select  @query

EXEC sp_executesql @query,N'@result int OUTPUT,@type int OUTPUT',@result,@type

select @result
select @type

如何解决,以及如何传递多个输出参数

解决方法

您需要说明分配给输出的内容;

set @query =’select @ result = count(*),@ type = Type_Code from Customers ….’

然后使用OUTPUT装饰输出;

EXEC sp_executesql @query,@result OUTPUT,@type OUTPUT

(您也可以通过“CUSTOMER 99”作为输入)

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读