如何在SQL Server 2008中将多个数据行设置为单个变量 [英] how to set multiple rows of data to a single variable in sql server 2008
本文介绍了如何在SQL Server 2008中将多个数据行设置为单个变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想将多个数据行分配给一个变量.
这是我的查询:-
Hi,
I want to assign multiple rows of data to a single variable.
this is my query:-
declare @resume as varchar(max)
set @resume=(select Resume from userdetails)
print @resume
Iam出现这样的错误:-
Iam getting error like this:-
Msg 512, Level 16, State 1, Line 2
Subquery returned more than 1 value. This is not permitted when the subquery follows =, !=, <, <= , >, >= or when the subquery is used as an expression.
请帮助我解决此问题
please help me to solve this problem
推荐答案
您不能这样.
但是,您可以使用表变量,请参见此处: http://odetocode.com/code/365.aspx [ ^ ]
You can''t like this.
However you can use a table variable see here : http://odetocode.com/code/365.aspx[^]
我认为您需要像这样的东西:
I think you need something like this :
declare @resume as varchar(max)
set @resume = ''
SELECT @resume = @resume + isnull(resume , '')
FROM userdetails
print @resume
如果要向它们添加分隔符,请使用此分隔符:
If you want to add a seperator to them use this one :
declare @resume as varchar(max)
set @resume = ''
SELECT @resume = @resume + isnull(resume , '') + ' - '
FROM userdetails
print @resume
希望对您有所帮助.
Hope it Helps.
这篇关于如何在SQL Server 2008中将多个数据行设置为单个变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文