sql连接创举,望高手指教 急急!!
有一个family表,有两个字段
pno pname
0006 刘妈妈
0006 刘爸爸
如何将查询出的结果写为一个字段并用逗号隔开
即 刘妈妈,刘爸爸
[解决办法]
declare @temp varchar(1000)select @temp=isnull(@r+',','')+pname from familyselect @temp
[解决办法]
呵呵,不知道楼上测试过没有,给楼主一个示例:
select A,B,step=convert(int,null),C= convert(varchar(255),null)
into #t
from OrgTable
order by A,B
go
declare @a varchar(10),@c varchar(255),@step
set @step = 0
set @c= ''
update #t
set C = case when A=@a then @c+''+B eles B end,
@c = case when A=@a then @c+''+B eles B end,
@a = A,
@step=@step+1,
step= @step
go
select A,C
into #t1
from #t
group by A
having step = max(step)
go
--result
/*
select * from #t1
go
drop table #t
drop table #t1
go