SQL Update Multiple Fields FROM via a SELECT Statement

后端 未结 6 1562
生来不讨喜
生来不讨喜 2020-12-29 18:50

This works, but i would like to remove the redundancy. Is there a way to merge the update with a single select statement so i don\'t have to use vars?

    DE         


        
6条回答
  •  悲哀的现实
    2020-12-29 19:37

    Something like this should work (can't test it right now - from memory):

    UPDATE SHIPMENT
    SET
      OrgAddress1     = BD.OrgAddress1,
      OrgAddress2     = BD.OrgAddress2,
      OrgCity         = BD.OrgCity,
      OrgState        = BD.OrgState,
      OrgZip          = BD.OrgZip,
      DestAddress1    = BD.DestAddress1,
      DestAddress2    = BD.DestAddress2,
      DestCity        = BD.DestCity,
      DestState       = BD.DestState,
      DestZip         = BD.DestZip
    FROM
       BookingDetails BD
    WHERE 
       SHIPMENT.MyID2 = @MyID2
       AND
       BD.MyID = @MyID
    

    Does that help?

提交回复
热议问题