select distinct * into aa from table delete table insert into table select * from aa select 职工一+职工二+职工三 as 职工 from table
select distinct * into aa from table delete table insert into table select * from aa select 职工一,职工二,职工三,职工一+职工二+职工三 as 职工 from table
select distinct * into aa from table delete table insert into table select * from aa drop table aa select 职工一,职工二,职工三,职工一+职工二+职工三 as 职工 from table
select case when 职工一=职工二 then 职工一+ case when 职工二=职工三 or 职工三=职工一 then '' else ','+职工三 end else 职工一+','+职工二+ case when 职工二=职工三 or 职工三=职工一 then '' else ','+职工三 end end from table
楼主的表结构是这样的吗? declare @table table (职工一 varchar(10),职工二 varchar(10),职工三 varchar(10)) --select * from @table insert into @table select 'A','B','C' UNION ALL select 'A','C','B' UNION ALL select 'B','D','C' UNION ALL select 'E','B','F' SELECT * FROM @TABLE================================== 在SQL Server 高手的大海中小心的行走 ==================================
declare @table table (职工一 varchar(10),职工二 varchar(10),职工三 varchar(10)) --select * from @table insert into @table select 'A','B','C' UNION ALL select 'A','C','B' UNION ALL select 'B','D','C' UNION ALL select 'E','B','F' SELECT * FROM @TABLEdeclare @t table (职工 varchar(10)) insert into @t select 职工一 from @TABLE union all select 职工二 from @TABLE union all select 职工三 from @TABLEselect distinct 职工 from @t ================================== 在SQL Server 高手的大海中小心的行走 ==================================
delete table
insert into table select * from aa
select 职工一+职工二+职工三 as 职工 from table
delete table
insert into table select * from aa
select 职工一,职工二,职工三,职工一+职工二+职工三 as 职工 from table
delete table
insert into table select * from aa
drop table aa
select 职工一,职工二,职工三,职工一+职工二+职工三 as 职工 from table
职工一+
case when 职工二=职工三 or 职工三=职工一 then '' else ','+职工三 end
else
职工一+','+职工二+
case when 职工二=职工三 or 职工三=职工一 then '' else ','+职工三 end
end
from table
declare @table table
(职工一 varchar(10),职工二 varchar(10),职工三 varchar(10))
--select * from @table
insert into @table
select 'A','B','C'
UNION ALL
select 'A','C','B'
UNION ALL
select 'B','D','C'
UNION ALL
select 'E','B','F' SELECT * FROM @TABLE==================================
在SQL Server 高手的大海中小心的行走
==================================
(职工一 varchar(10),职工二 varchar(10),职工三 varchar(10))
--select * from @table
insert into @table
select 'A','B','C'
UNION ALL
select 'A','C','B'
UNION ALL
select 'B','D','C'
UNION ALL
select 'E','B','F'
SELECT * FROM @TABLEdeclare @t table
(职工 varchar(10))
insert into @t
select 职工一 from @TABLE
union all
select 职工二 from @TABLE
union all
select 职工三 from @TABLEselect distinct 职工 from @t
==================================
在SQL Server 高手的大海中小心的行走
==================================