将多个结果合并到一个字段中 [英] getting multiple results into a single field
本文介绍了将多个结果合并到一个字段中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何从查询中获取多个结果到单个字段中?
我正在尝试...
how to get multiple results fetched from a query into single field??
i am trying this...
declare @uname varchar(max)
select @uname = (select uname from users)
但这是错误的...
but it is wrong...
so could anyone tell me the right way to do this??
推荐答案
不能将select
语句分配给这样的标量变量.
但是,您可以创建一个TABLE
变量,请参见此处的示例:
http://odetocode.com/code/365.aspx [
Aselect
statement cannot be assigned to a scalar variable like this.
You can however create aTABLE
variable, see here for examples :
http://odetocode.com/code/365.aspx[^]
您不能将多个项目放在单个变量中.一种方法是使用游标迭代结果.请参阅: DECLARE CURSOR [
You cannot place multiple items in a single variable. One way to do this is to iterate the results using a cursor. See: DECLARE CURSOR [^].
However, if possible, what ever you''re doing, it would be more efficient if the operation could be done set based.
如果您不知道该信息,请使用游标我可以为光标编写代码
use cursor for that if u don''t know about i can write a code for cursor
这篇关于将多个结果合并到一个字段中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文