Update data

  • I need your expertise. I'm trying to update the values of all column from tbl_a with the values from tbl_b base on the conditions listd. Here is what I have

    update tbl_a

    set tbl_a.column1 = tbl_b.column1,

    set tbl_a.column2 = tbl_b.column2,

    set tbl_a.column3 = tbl_b.column3,

    set tbl_a.column4 = tbl_b.column4,

    set tbl_a.column5 = tbl_b.column5,

    set tbl_a.column6 = tbl_b.column6

    from tbl_a,tbl_b

    --join tbl_b

    --on tbl_a.key_id = tbl_b.key_id

    where tbl_a.column5 = tbl_b.column5

    and tbl_a.column6 = tbl_b.column6

    when I check the syntax, I receive this message

    Server: Msg 156, Level 15, State 1, Line 29

    Incorrect syntax near the keyword 'set'.

    it points to the second set statement in the query. Can you please tell me what is wrong with this query. Your help is greatly appreciated.

  • You only need one SET keyword; i.e.:

    update tbl_a

    set tbl_a.column1 = tbl_b.column1,

    tbl_a.column2 = tbl_b.column2,

    tbl_a.column3 = tbl_b.column3,

    tbl_a.column4 = tbl_b.column4,

    tbl_a.column5 = tbl_b.column5,

    tbl_a.column6 = tbl_b.column6

    from tbl_a,tbl_b

    --join tbl_b

    --on tbl_a.key_id = tbl_b.key_id

    where tbl_a.column5 = tbl_b.column5

    and tbl_a.column6 = tbl_b.column6



    --Jonathan

  • Jonathan, that works great!!!Thank you so much...

    I also add an important criteria to the where clause

    tbl_a.key_id = tbl_b.key_id.

    my WHERE clause now look like this:

    tbl_a.key_id = tbl_b.key_id

    and tbl_a.column5 = tbl_b.column5

    and tbl_a.column6 = tbl_b.column6

Viewing 3 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply