Update Table based on a join with the existing table

  • Hi,

    I was to update a table based on a join with the existing table.

    UPDATE OPT_SalesForecastDetail det, OPT_TmpSalesForecast tmp

    SET  det.SFDT_QtyMonth1=tmp.TMSF_QtyMonth1,

     det.SFDT_QtyMonth2=tmp.TMSF_QtyMonth2,

     det.SFDT_QtyMonth3=tmp.TMSF_QtyMonth3,

     det.SFDT_VendRemarks= tmp.TMSF_VendRemarks,

     det.SFDT_VersionNo=SFDT_VersionNo+1

    WHERE det.SFDT_SalesPlanCode='SF012005GEN0031'

    AND tmp.TMSF_PackCode = det.SFDT_PackCode

    AND (tmp.TMSF_QtyMonth1 <> det.SFDT_QtyMonth1

    OR tmp.TMSF_QtyMonth2 <> det.SFDT_QtyMonth2

    OR tmp.TMSF_QtyMonth3 <> det.SFDT_QtyMonth3

    OR det.SFDT_VendRemarks <> tmp.TMSF_VendRemarks)

     

    This does not work please give ur comments

  • UPDATE det

    SET  SFDT_QtyMonth1=tmp.TMSF_QtyMonth1, 

     SFDT_QtyMonth2=tmp.TMSF_QtyMonth2,

     SFDT_QtyMonth3=tmp.TMSF_QtyMonth3,

     SFDT_VendRemarks= tmp.TMSF_VendRemarks,

     SFDT_VersionNo=SFDT_VersionNo+1

    from OPT_SalesForecastDetail det

    inner join OPT_TmpSalesForecast tmp 

    on det.SFDT_SalesPlanCode='SF012005GEN0031'

    AND tmp.TMSF_PackCode = det.SFDT_PackCode

    WHERE (tmp.TMSF_QtyMonth1 <> det.SFDT_QtyMonth1

    OR tmp.TMSF_QtyMonth2 <> det.SFDT_QtyMonth2

    OR tmp.TMSF_QtyMonth3 <> det.SFDT_QtyMonth3

    OR det.SFDT_VendRemarks <> tmp.TMSF_VendRemarks)

    Johan

    Learn to play, play to learn !

    Dont drive faster than your guardian angel can fly ...
    but keeping both feet on the ground wont get you anywhere :w00t:

    - How to post Performance Problems
    - How to post data/code to get the best help[/url]

    - How to prevent a sore throat after hours of presenting ppt

    press F1 for solution, press shift+F1 for urgent solution 😀

    Need a bit of Powershell? How about this

    Who am I ? Sometimes this is me but most of the time this is me

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

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