SQL字符串合并
create table #tb(id int, value varchar(10),cname varchar(20))
创新互联专注为客户提供全方位的互联网综合服务,包含不限于成都做网站、网站建设、外贸营销网站建设、浦江网络推广、小程序制作、浦江网络营销、浦江企业策划、浦江品牌公关、搜索引擎seo、人物专访、企业宣传片、企业代运营等,从售前售中售后,我们都将竭诚为您服务,您的肯定,是我们最大的嘉奖;创新互联为所有大学生创业者提供浦江建站搭建服务,24小时服务热线:13518219792,官方网址:www.cdcxhl.com
insert into #tb values(1, 'aa','aaaa')
insert into #tb values(1, 'bb','eeee')
insert into #tb values(1, 'aa','tttt')
insert into #tb values(2, 'aaa','gggg')
insert into #tb values(2, 'bbb',null)
insert into #tb values(2, 'ccc','hhhh')
insert into #tb values(1, 'cc','llll')
go
----
---去重 select id, [value] = stuff((select distinct ',' + [value] from #tb t where id = #tb.id for xml path('')) , 1 , 1 , ''),max(isnull(cname,'')) from #tb group by id ---不去重 select id, [value] = stuff((select ',' + [value] from #tb t where id = #tb.id for xml path('')) , 1 , 1 , ''),max(isnull(cname,'')) from #tb group by id
drop table #tb
网页名称:SQL字符串合并
文章转载:http://pwwzsj.com/article/ipdogp.html