表 人员 中有三个字段:职工一,职工二,职工三
其中三个字段中可能会有重复的值,就是说在职工一中出现过的人也可以在职工二或三中出现,如何将这三个字段的值合并成一个字段“职工”,并且删除重复值?

解决方案 »

  1.   

    select distinct * into aa from table
    delete table
    insert into table select * from aa
    select 职工一+职工二+职工三 as 职工 from table
      

  2.   

    select distinct * into aa from table
    delete table
    insert into table select * from aa
    select 职工一,职工二,职工三,职工一+职工二+职工三 as 职工 from table
      

  3.   

    select distinct * into aa from table
    delete table
    insert into table select * from aa
    drop table aa
    select 职工一,职工二,职工三,职工一+职工二+职工三 as 职工 from table
      

  4.   

    select case when 职工一=职工二 then
    职工一+
    case when 职工二=职工三 or 职工三=职工一 then '' else ','+职工三 end      
           else
    职工一+','+职工二+
    case when 职工二=职工三 or 职工三=职工一 then '' else ','+职工三 end
    end
    from table
      

  5.   

    楼主的表结构是这样的吗?
    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 高手的大海中小心的行走
    ==================================
      

  6.   

    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 高手的大海中小心的行走
    ==================================