HLyder
asked on
SQL UNION AGGREGATE FUNCTION
I am creating an SQL query which (simplified) looks like
SELECT SUM(quantity) FROM ItemSales
WHERE UnitID = 1
UNION
SELECT SUM(quantity) FROM ProductionLoss
WHERE UnitID = 1
The above would give me a table with 2 lines, one for each select.
Question: How can I get an aggregate result yielding only a single result as the sum of the 2 rows produced.
Is there a way to do this without using temporary tables and stored procedures.
SELECT SUM(quantity) FROM ItemSales
WHERE UnitID = 1
UNION
SELECT SUM(quantity) FROM ProductionLoss
WHERE UnitID = 1
The above would give me a table with 2 lines, one for each select.
Question: How can I get an aggregate result yielding only a single result as the sum of the 2 rows produced.
Is there a way to do this without using temporary tables and stored procedures.
ASKER
Yes it looks just like what I am looking for but the query is returning an error message indicating incorrect syntax from the [Microsoft ODBC SQL Server Driver] pointing to the last ) in the statement.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
you rock, thanks
Open in new window