Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Query based on query help

Author  Topic 

snowber
Starting Member

1 Post

Posted - 2010-03-04 : 18:04:20
Hey guys,

I have this query:

SELECT ORDER_LINE_T.Product_ID, Standard_Price,
SUM(ORDER_LINE_T.Ordered_Quantity)*Standard_Price AS Total
FROM PRODUCT_T
WHERE PRODUCT_T.Product_ID=ORDER_LINE_T.Product_ID
AND ORDER_LINE_T.Order_ID=1
GROUP BY ORDER_LINE_T.Product_ID, Standard_Price
;


Which gives me totals of a certain order, now I want to take those TOTALS and add them up in another query to get the "Total of the totals", how can I do this?

Thanks!

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2010-03-04 : 23:09:49
[code]
select sum(Total)
from
(

SELECT ORDER_LINE_T.Product_ID, Standard_Price,
SUM(ORDER_LINE_T.Ordered_Quantity)*Standard_Price AS Total
FROM PRODUCT_T
WHERE PRODUCT_T.Product_ID=ORDER_LINE_T.Product_ID
AND ORDER_LINE_T.Order_ID=1
GROUP BY ORDER_LINE_T.Product_ID, Standard_Price

) q
[/code]


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2010-03-05 : 10:08:57
actually if this reqmnt is for a report no need to do it in query, you can just do summation inside report.

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -