62,052
社区成员
发帖
与我相关
我的任务
分享
create table A(ID int,客户名称 nvarchar(40),第四列 nvarchar(100),第五列 nvarchar(100))
insert into A
select 140,'张三','1','|1||141|' union all
select 141,'管理员','140','|1|140|' union all
select 1,'李四','141','|1|140|141|'
select distinct ID,客户名称 into temp
from A
select ID,客户名称,
第四列=stuff((select '|'+ 客户名称 from temp
where charindex('|' + rtrim(id)+'|','|' + A.第四列+'|')>0 for xml path('')),1,1,''),
第五列=stuff((select '|'+ 客户名称 from temp
where charindex('|' + rtrim(id)+'|','|' + A.第五列+'|')>0 for xml path('')),1,1,'|') + '|'
from A group by id,第四列,客户名称,第五列
drop table A;
drop table temp;