Updating one table from another using a thrid table

  • I'm trying to update a description in a label table(imlabel_sql) by using the master inventory table's description (imitmidx_sql) and selecting my item nubmers that need updating from a table with just the numbers of inventory that need updating(lbl_crt). Here is what I thought was a correct query:

    begin tran update imlabel_sql

    set imlabel_sql.description = imitmidx_sql.item_desc_1

    from imitmidx_sql

    where rtrim(ltrim(imitmidx_sql.itemno)) in

    ( select itemno

    from lbl_crt)

    table1=imlabel_sql

    table2=imitmidx_sql

    table3=lbl_crt

    Where did I go WRONG?????? :angry:

  • Please see this link for instructions on how to get better results from these forums: http://www.sqlservercentral.com/articles/Best+Practices/61537/

    [font="Times New Roman"]-- RBarryYoung[/font], [font="Times New Roman"] (302)375-0451[/font] blog: MovingSQL.com, Twitter: @RBarryYoung[font="Arial Black"]
    Proactive Performance Solutions, Inc.
    [/font]
    [font="Verdana"] "Performance is our middle name."[/font]

  • you have not specified any join condition between imlabel_sql and imitmidx_sql. so, imlabel_sql.description will have arbitrary values from imitmidx_sql.item_desc_1.

    also, unless your app really allows imitmidx_sql.itemno to have leading spaces, there's no reason to l/rtrim it.

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

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