日期:2014-05-17 浏览次数:20796 次
if object_id('[tb]') is not null drop table [tb]
go
create table [tb]([id] int,[sid] int,[liuyan] varchar(12))
insert [tb]
select 1,3,'很好的' union all
select 2,3,'什么东东' union all
select 3,3,'要下雨了' union all
select 4,4,'我的书啊' union all
select 5,5,'看什么的电影' union all
select 6,3,'吃饭不管事' union all
select 7,4,'眼睛听话' union all
select 8,5,'不要说话' union all
select 9,7,'风雨无阻' union all
select 10,9,'来了去了' union all
select 11,8,'不是不是' union all
select 12,7,'欧洲杯歇了' union all
select 13,9,'不要管了'
go
select row_number() over(order by getdate()) as id,
sid,
liuyan=stuff((select ','+liuyan from tb where sid=t.sid for xml path('')),1,1,'')