declare @Pipno varchar(500)
select @Pipno = (V_3) from REPORTDATE // here V-3 contain more than five rows
select @Pipno
Run Code Online (Sandbox Code Playgroud)
但是在select @Pipno中只打印一行(即最大V_3)我想在这个@Pipno变量中存储所有五行或更多行请回复我
您可以使用表变量.
declare @Pipno table(V_3 varchar(500))
insert into @Pipno
select V_3
from REPORTDATE
select V_3
from @Pipno
Run Code Online (Sandbox Code Playgroud)
或者,如果您希望将结果作为一个字符串.
declare @Pipno varchar(500)
set @Pipno = ''
select @Pipno = @Pipno + V_3 + ' '
from REPORTDATE
select @Pipno
Run Code Online (Sandbox Code Playgroud)