Update Procedure

  • Situation, I need to sum up data in a table A and then update table B, with the data in table A.

    Normally I would Create a temp table and insert all the selected/sumed data (table A) into the temp table, then update table A from the temp table.

    Does anyone have a better way to do this?  Maybe an update statement with a subquery?

  • It will be VERY helpful if you post the DDL of the tables and Columns involved

    but here is a hint

    Update a set aggregateOnA = DSum.TheSum

    From TableA a

         join (

                Select ID, Sum(Q) TheSum

                from TableB

                Group by ID

              ) DSum

          on a.ID = DSum.ID

     


    * Noel

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

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