Overhead remove using query(combine 2 statement into one )

  • hi

    We need to combine two DML Statement into one statment

    update B

    Set B.phone_disp_new = ISNULL(A.value,'Other')

    from test22 B

    left outer join test21 A

    on B.ph_phone_new = A.TGA_CODE

    update B

    Set B.phone_disp_old = ISNULL(A.value,'Other')

    from test22 B

    left outer join test21 A

    on B.ph_phone_old = A.TGA_CODE

    Can we do it in one update statement?

  • Please post sample data. Will get back to you.

    ~ Lokesh Vij


    Guidelines for quicker answers on T-SQL question[/url]
    Guidelines for answers on Performance questions

    Link to my Blog Post --> www.SQLPathy.com[/url]

    Follow me @Twitter

  • harrd007 (7/28/2012)


    hi

    We need to combine two DML Statement into one statment

    update B

    Set B.phone_disp_new = ISNULL(A.value,'Other')

    from test22 B

    left outer join test21 A

    on B.ph_phone_new = A.TGA_CODE

    update B

    Set B.phone_disp_old = ISNULL(A.value,'Other')

    from test22 B

    left outer join test21 A

    on B.ph_phone_old = A.TGA_CODE

    Can we do it in one update statement?

    Is this what you want?

    update B

    set

    B.phone_disp_new = ISNULL(A.value,'Other'),

    C.phone_disp_old = ISNULL(B.value,'Other')

    from

    test22 B left outer join test21 A

    on B.ph_phone_new = A.TGA_CODE

    left outer join test21 C

    on C.ph_phone_old = A.TGA_CODE

    Tom

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

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