当前位置: 代码迷 >> Sql Server >> 如何把查出的多个结果赋给一个变量
  详细解决方案

如何把查出的多个结果赋给一个变量

热度:18   发布时间:2016-04-27 13:19:25.0
怎么把查出的多个结果赋给一个变量
我在写存储过程的时候用到

SQL code
declare @productid varchar(300)set @productid=(select from vw_bill_list)报错 服务器: 消息 512,级别 16,状态 1,过程 BILL_FEE,行 31子查询返回的值多于一个。当子查询跟随在 =、!=、<、<=、>、>= 之后,或子查询用作表达式时,这种情况是不允许的。


执行select product from vw_bill_list 结果是
product 
45
46

结果有多个不能用set赋值,
[email protected]='45,46'

帮帮忙这怎么写
我用的SqlServer


------解决方案--------------------
好像要用游标
------解决方案--------------------
SQL code
declare @productid varchar(300)set @productid=('select * from vw_bill_list')
------解决方案--------------------
用游標了 

------解决方案--------------------
SQL code
declare @productid varchar(300)select @productid= isnull(@productid+',','') + cast(product as varchar(20))from vw_bill_listprint @productid
------解决方案--------------------
SQL code
--支持海爷declare @productid varchar(300)select   @productid= isnull(@productid+',','') + cast(product as varchar(20))from   vw_bill_listexec(@productid)
------解决方案--------------------
SQL code
declare @productid varchar(300)select @productid=isnull(@productid+',','')+ ltrim(product) from tbprint @productid
------解决方案--------------------
探讨
SQL [email protected](300)[email protected]=isnull(@productid+',','')+cast(productasvarchar(20))from [email protected]
  相关解决方案