update 表
set ID3=(select min(ID3) from 表 where ID2=b.ID2)
from 表 a
inner join INSERTED b on a.ID=b.ID

解决方案 »

  1.   

    create table tb (id int identity(1,1),id2 char(2) ,id3 char(5))insert tb select 'A','safs'
    insert tb select 'B','dafs'
    insert tb select 'C',Null
    insert tb select 'C','ASS'go
    select * from tb
    go
    create trigger trigger_insert
    on tb
    for insert
    as
    begin
    update a
        set ID3=(select min(ID3) from tb where ID2=b.ID2)
    from tb a
        inner join INSERTED b on a.ID=b.ID
    endgo
    insert tb select 'C',nullselect * from tb
    /*id          id2  id3   
    ----------- ---- ----- 
    1           A    safs 
    2           B    dafs 
    3           C    NULL
    4           C    ASS  
    5           C    ASS  
    */
    drop table tb
      

  2.   

    create trigger T_insert on Ta
    after insert
    as
    begin
    update T
    set ID3=(select top 1 ID3 from T where ID2=t.ID2 and ID3 is not null order by newID() )
    from inserted i join ta t
    on  T.ID=i.ID
    end
      

  3.   

    感谢!昨夜小楼,无枪的狙击手,还有roy_88 ,尤其感谢无枪的狙击手!呵呵~~按照无枪的狙击手提供的已经解决了!圆满结贴!