日期:2014-05-17  浏览次数:20483 次

如何把结果集放在一个字段里保存
DECLARE @arrChildID NVARCHAR(50) 
select arrChildID= nodeid from nodes where ParentID=1

结果:
  arrChildID
1 12
2 15
3 18
4 20
5 25

问:把结果集放在一个字段里保存
update .........set A='12,15,18,20,25'



------解决方案--------------------
SQL code
DECLARE @arrChildID NVARCHAR(50)  
select @arrChildID=isnull(@arrChildID+','.'')+nodeid from nodes where ParentID=1
select @arrChildID

------解决方案--------------------
DECLARE @arrChildID NVARCHAR(50)
select @arrChildID =rtrim(nodeid)+','+@arrChildID from nodes where ParentID=1
update .........set A=@arrChildID
------解决方案--------------------
探讨

SQL code
DECLARE @arrChildID NVARCHAR(50)
select @arrChildID=isnull(@arrChildID+','.'')+nodeid from nodes where ParentID=1
select @arrChildID

------解决方案--------------------
这个可能跟你原表情况类似一些
SQL code
create table nodes( nodeid varchar(10))
insert into nodes
select '12' union all
select '15' union all
select '18' union all
select '20' union all
select '25'


declare @arrChildID varchar(500)

select @arrChildID=isnull(@arrChildID+',','')+nodeid from nodes

select  @arrChildID

update  updated_tb set updated_col=@arrChildID

------解决方案--------------------
探讨

引用:

SQL code
DECLARE @arrChildID NVARCHAR(50)
select @arrChildID=isnull(@arrChildID+','.'')+nodeid from nodes where ParentID=1
select @arrChildID


.改为,