select distinct stuff(email,1,charindex('@',email)+1,'')
into deal_cd1
from domain_db..un_cd1
where charindex('@',email)>0

解决方案 »

  1.   

    --如果表deal_c已经存在insert into deal_cd1
    select distinct stuff(email,1,charindex('@',email)+1,'')
    from domain_db..un_cd1
    where charindex('@',email)>0
      

  2.   

    --改一下,如果生成表
    select distinct 域名=stuff(email,1,charindex('@',email),'')
    into deal_cd1
    from domain_db..un_cd1
    where charindex('@',email)>0--如果表deal_c已经存在insert into deal_cd1
    select distinct stuff(email,1,charindex('@',email),'')
    from domain_db..un_cd1
    where charindex('@',email)>0
      

  3.   

    --测试--测试数据
    create table un_cd1(email varchar(200))
    insert un_cd1 select '[email protected]'
    union  all    select '[email protected]'
    union  all    select '[email protected]'
    union  all    select '[email protected]'
    go--处理
    select distinct 域名=stuff(email,1,charindex('@',email),'')
    into deal_cd1
    from un_cd1
    where charindex('@',email)>0--显示处理结果
    select * from deal_cd1
    go--删除测试
    drop table deal_cd1,un_cd1/*--测试结果
    域名                        
    ----------------------------
    126.com
    163.com
    tom.com(所影响的行数为 3 行)--*/