本帖最后由 yelang771 于 2011-12-01 13:09:29 编辑

解决方案 »

  1.   

    update a set sn=(select max(sn) from tb where delno=a.delno)
    from tb a
      

  2.   

    ----------------------------------------------------------------
    -- Author  :fredrickhu(小F,向高手学习)
    -- Date    :2011-12-01 13:40:47
    -- Version:
    --      Microsoft SQL Server 2008 R2 (RTM) - 10.50.1617.0 (Intel X86) 
    -- Apr 22 2011 11:57:00 
    -- Copyright (c) Microsoft Corporation
    -- Enterprise Evaluation Edition on Windows NT 6.1 <X64> (Build 7600: ) (WOW64)
    --
    ----------------------------------------------------------------
    --> 测试数据:[tb]
    if object_id('[tb]') is not null drop table [tb]
    go 
    create table [tb]([index] int,[delno] int,[sn] int)
    insert [tb]
    select 1,111,1 union all
    select 2,111,null union all
    select 3,112,null union all
    select 4,112,2 union all
    select 5,112,null
    --------------开始查询--------------------------
    update a set sn=b.sn from tb a,(select * from tb where sn is not null) b where a.delno=b.delnoselect * from tb 
    ----------------结果----------------------------
    /* index       delno       sn
    ----------- ----------- -----------
    1           111         1
    2           111         1
    3           112         2
    4           112         2
    5           112         2(5 行受影响)*/