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?
    DECLARE         @OrgAddress1 varchar,         @OrgAddress2 varchar,         @OrgCity varchar,         @OrgState varchar,         @OrgZip varchar,         @DestAddress1 varchar,         @DestAddress2 varchar,         @DestCity varchar,         @DestState varchar,         @DestZip varchar      SELECT          @OrgAddress1    =   OrgAddress,         @OrgAddress2    =   OrgAddress2,         @OrgCity        =   OrgCity,         @OrgState       =   OrgState,         @OrgZip         =   OrgZip,         @DestAddress1   =   DestAddress,         @DestAddress2   =   DestAddress2,         @DestCity       =   DestCity,         @DestState      =   DestState,         @DestZip        =   DestZip     FROM          ProfilerTest.dbo.BookingDetails      WHERE          MyID=@MyID      UPDATE SHIPMENT     SET         OrgAddress1     =   @OrgAddress1,         OrgAddress2     =   @OrgAddress2,         OrgCity         =   @OrgCity,         OrgState        =   @OrgState,         OrgZip          =   @OrgZip,         DestAddress1    =   @DestAddress1,         DestAddress2    =   @DestAddress2,         DestCity        =   @DestCity,         DestState       =   @DestState,         DestZip         =   @DestZip     WHERE          MyID2=@ MyID2 
                The UPDATE statement in SQL is used to update the data of an existing table in database. We can update single columns as well as multiple columns using UPDATE statement as per our requirement. UPDATE table_name SET column1 = value1, column2 = value2,...
We can update multiple columns by specifying multiple columns after the SET command in the UPDATE statement. The UPDATE statement is always followed by the SET command, it specifies the column where the update is required.
To update multiple columns use the SET clause to specify additional columns. Just like with the single columns you specify a column and its new value, then another set of column and values. In this case each column is separated with a column.
UPDATE config SET t1. config_value = 'value' , t2. config_value = 'value2' WHERE t1. config_name = 'name1' AND t2.
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?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With