本帖最后由 AthlonXP2000 于 2012-05-16 12:24:45 编辑

解决方案 »

  1.   


    --> 测试数据:[t1]
    if object_id('[t1]') is not null 
    drop table [t1]
    create table [t1](
    [cn] varchar(3),
    [phone] int,
    [bm] int,
    [address] varchar(6)
    )
    insert [t1]
    select 'abc',111111,22222,'123abc'
    --> 测试数据:[t2]
    if object_id('[t2]') is not null drop table [t2]
    create table [t2](
    [cn] varchar(3),
    [phone] int,
    [bm] int,
    [address] varchar(6),
    [ckphone] sql_variant,
    [ckbm] sql_variant,
    [ckaddress] sql_variant
    )
    insert [t2]
    select 'abc',111111,22223,'abc123',null,null,nullupdate t2
    set [ckphone]=t.phone,[ckbm]=t.bm,[ckaddress]=t.[address]
    from(
    select * from t1 a where  not exists(
    select 1 from t2 b where a.cn=b.cn and a.phone<>b.phone
    ))t where t.cn=t2.cnselect * from t2
    /*
    cn phone bm address ckphone ckbm ckaddress
    abc 111111 22223 abc123 111111 22222 123abc
    */