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 2000 Forums
 SQL Server Development (2000)
 GROUP BY date range

Author  Topic 

Scott
Posting Yak Master

145 Posts

Posted - 2002-02-21 : 07:10:18
I have a table with a date field and a money field

I want the total money spent in each financial year (1 April to 31 March)

Sum(Money field) ... group by financial year???

robvolk
Most Valuable Yak

15732 Posts

Posted - 2002-02-21 : 07:21:15
SELECT DateName(year, DateAdd(qq, -1, dateColumn)) FinancialYear,
Sum(moneyColumn) Total
FROM myTable
GROUP BY DateName(year, DateAdd(qq, -1, dateColumn))


DateAdd will subtract 1 quarter from the date column in your table; this will move dates before April 1 into the previous year, then DateName will extract the year and GROUP on it.

Go to Top of Page
   

- Advertisement -