sql server trigger help - same table update

后端 未结 1 1435
[愿得一人]
[愿得一人] 2021-01-27 19:15

I posted a similar question earlier - but can\'t seem to get a long enough response! Sorry if I shouldn\'t be posting again!

This is using SQL Server 2008. I have a tabl

相关标签:
1条回答
  • 2021-01-27 19:51
    create trigger [dbo].[test] on [dbo].[invoice]
    for insert
    as
    begin
    
    update Invoice
      set Trader_Status = 'OPEN'
      where Invoice_Id in ( select Invoice_Id from inserted where Invoice_Status = 'PENDING' )
    
    update Invoice
      set Trader_Status = 'BLOCKED'
      where Invoice_Id in ( select Invoice_Id from inserted where Invoice_Status = 'OVERDUE' )
    
    end
    

    Note that this will handle more than one row being inserted by a single statement.

    0 讨论(0)
提交回复
热议问题