update b set 商家编号=a.商家编号 from  a,b where b.卡号 between 号段起 and 号段终

解决方案 »

  1.   

    create table Am(商家编号 varchar(10), 号段起 int, 号段终 int)
    insert Am select 'cd0001' ,1 ,10
    union all select 'cd0002' ,11, 20
    union all select 'cd0003' ,21, 30create table Bm(卡号 int, 商家编号 varchar(10))
    insert bm select 1, null
    union all select 2 ,null 
    union all select 3, null
    union all select 4, null 
    union all select 5, null
    union all select 6, null
    union all select 7, null
    union all select 8, null
    union all select 9, null
    union all select 10, null
    union all select 11, null
    union all select 12, null
    union all select 13, null
    union all select 14, null
    update bm set 商家编号=am.商家编号 from am,bm where bm.卡号 between 号段起 and 号段终select * from bm
      

  2.   

    卡号          商家编号       
    ----------- ---------- 
    1           cd0001
    2           cd0001
    3           cd0001
    4           cd0001
    5           cd0001
    6           cd0001
    7           cd0001
    8           cd0001
    9           cd0001
    10          cd0001
    11          cd0002
    12          cd0002
    13          cd0002
    14          cd0002(所影响的行数为 14 行)