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)
 How To SUM previous SUM columns

Author  Topic 

Lacool
Starting Member

2 Posts

Posted - 2010-03-04 : 19:49:20
Hi, I have a query which SUMS the values of a couple of columns as per below. I want to be able to SUM the results of 'Total Loc Fee' and 'Total Card Fee', is this possible in the same query.

SELECT UserName, DateInserted, SUM(NoLocations * 1.50) AS 'Total Loc Fee', SUM(CardFee * 11.00) AS 'Total Card Fee'
FROM dbo.tblChargeHistory
GROUP BY UserName, DateInserted

Many Thanks

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2010-03-04 : 22:49:58
[code]
SELECT UserName, DateInserted,
SUM(NoLocations * 1.50) AS 'Total Loc Fee',
SUM(CardFee * 11.00) AS 'Total Card Fee',
SUM(SUM(NoLocations * 1.50)) over () as [Grand Total Loc Fee],
SUM(SUM(CardFee * 11.00)) over () as [Grand Total Card Fee]
FROM dbo.tblChargeHistory
GROUP BY UserName, DateInserted
[/code]


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

Go to Top of Page

Lacool
Starting Member

2 Posts

Posted - 2010-03-06 : 00:19:04
Many thanks, your help is appreciated
Go to Top of Page
   

- Advertisement -