views:

1406

answers:

2

Hi,

I have a union all query in a stored procedure.

WHat I would like to do is Sum a column and return that query to the client

How would I do this?

Malcolm

A: 
SELECT SUM(MyCol) FROM
(
SELECT ... MyCol FROM Table1
UNION
SELECT ... MyCol FROM Table2
)
Joe
+1  A: 
SELECT
    othercol1, othercol2,
    SUM(bar)
FROM
    (
    SELECT
       othercol1, othercol2, bar
    FROM
       RT
    UNION ALL
    SELECT
       othercol1, othercol2, bar
    FROM
       FM
    ) foo
GROUP BY
    othercol1, othercol2
gbn