简体   繁体   English

如何在SQL Server存储过程变量中获得多个值

[英]how to get more than one value in sql server stored procedure variable

declare @Pipno varchar(500)
select @Pipno = (V_3) from REPORTDATE // here V-3 contain more than five rows
select @Pipno

but in select @Pipno prints only one row (ie, max of V_3) i want to store all five or more rows in this @Pipno variable please reply me 但在选择@Pipno中仅打印一行(即V_3的最大值),我想在此@Pipno变量中存储所有五行或更多行,请回复我

You can use a table variable. 您可以使用表变量。

declare @Pipno table(V_3 varchar(500))

insert into @Pipno
select V_3 
from REPORTDATE

select V_3
from @Pipno

Or if you want the result as one string. 或者,如果您希望将结果作为一个字符串。

declare @Pipno varchar(500)
set @Pipno = ''

select @Pipno = @Pipno + V_3 + ' '
from REPORTDATE

select @Pipno

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM