Results 1 to 2 of 2

Thread: tsql help!

  1. #1
    st Guest

    tsql help!


    simple update, I want to update max_seq with max(0rdr_seq) from another table.
    how do you?

    update h
    set max_seq = d.max(ordr_seq)
    from h_drug_stage_dup h
    join drug_ordr_stage d
    on h.patkey = d.patkey and
    h.ordr_dtm= d.ordr_dtm and
    h.h_drug = d.h_Drug


  2. #2
    Dale Shaw Guest

    tsql help! (reply)

    Hi

    Corelated sub-query:

    UPDATE SalesSum SS
    SET YTDsales=
    (
    SELECT sum(qty) As YTDsales
    FROM ProductSales PS
    WHERE OrderDate BETWEEN '1-jan-01' AND getdate()
    AND PS.ProductID=SS.ProductID
    )

    The last line forces the inner query to recalculate for EACH product in the outer query.


    Dale


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •