通过一个udpate语句修改标识bs列,把标识bs为null的填上相同域名ym的bs列的值。
id[主键] ym[域名]          bs[标识] sfyx[是否有效]
12273 witmesh.com 3853857 0
12274 witmesh.com NULL 0
12275 witmesh.com NULL 1
12276 sqlmx.cn 3853857 0
12277 sqlmx.cn NULL 1

解决方案 »

  1.   


    update a
    set a.bs = (select top 1 bs from tb where ym=a.ym where bs is not null order by id)
    from tb a
      

  2.   

    update a
    set a.bs = (select  max(bs) from tb where ym=a.ym)
    from tb a
      

  3.   


    update a
    set a.bs = isnull((select top 1 bs from tb where ym=a.ym where bs is not null order by id),a.bs)
    from tb a