A列中有B列中的数据库也更新为存在,不相同为0
B列中有A列中的数据库也更新为存在,不相同为0谢谢!如:
A B C
111111111111 333333333333 存在
222222222222 212422114124 0
333333333333 555555555555 存在
888888888888 211222242244 0
555555555555 RW3345464544 0
444444444444 888888888888 存在
999999999999 234253464777 0

解决方案 »

  1.   

    if object_id('[tb]') is not null drop table [tb]
    go
    create table [tb]([A] varchar(12),[B] varchar(12),[C] varchar(4))
    insert [tb]
    select '111111111111','333333333333',' ' union all
    select '222222222222','212422114124',' ' union all
    select '333333333333','555555555555',' ' union all
    select '888888888888','211222242244',' ' union all
    select '555555555555','RW3345464544',' ' union all
    select '444444444444','888888888888',' ' union all
    select '999999999999','234253464777',' '
    goupdate t
    set c=case when exists(select 1 from tb where a=t.b) then '存在' else '0' end
    from tb t
    goselect * from tb
    /**
    A            B            C
    ------------ ------------ ----
    111111111111 333333333333 存在
    222222222222 212422114124 0
    333333333333 555555555555 存在
    888888888888 211222242244 0
    555555555555 RW3345464544 0
    444444444444 888888888888 存在
    999999999999 234253464777 0(7 行受影响)
    **/
      

  2.   


    意思是A表中有B中的数据或者B中有A的数据都更新为存在,否则为0
      

  3.   

    因为B=33333333,然后去查找所有的A,是否存在33333333此值,
    然后在每三行,找到333333333333 55555555555,所以存在
    并不是列要对应,只要某 一行存在就行 了.所以使用exists