Is there a way to SELECT and UPDATE rows at the same time?

后端 未结 9 1532
醉话见心
醉话见心 2020-12-12 21:01

I\'d like to update a set of rows based on a simple criteria and get the list of PKs that were changed. I thought I could just do something like this but am worried about po

9条回答
  •  抹茶落季
    2020-12-12 21:25

    Perhaps something more like this?

    declare @UpdateTime datetime
    
    set @UpdateTime = getutcdate()
    
    update Table1 set AlertDate = @UpdateTime where AlertDate is null
    
    select ID from Table1 where AlertDate = @UpdateTime
    

提交回复
热议问题