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
 Transact-SQL (2000)
 Quaterly data from the selected Range

Author  Topic 

stsj
Starting Member

9 Posts

Posted - 2003-04-12 : 04:44:08
Hi all,

I have one table with period data time and composite integer
now i want to select the sum(composite) for quaterly like
if user selects 200001 to 200203 i want all the quater which fall under the selection/
in this we have q1.q2.q3.q4 of 2000 and
q1.q2.q3.q4 of 2001 and q1.q2.q3.q4 of 2002 and q1 20003...i want all those quaters..each one row....
so how to do that let me know the query ....

mohdowais
Sheikh of Yak Knowledge

1456 Posts

Posted - 2003-04-12 : 09:38:50
SELECT DATEPART(qq, PeriodDataTime) AS Quarter, DATEPART(yy, PeriodDataTime) AS Year, SUM(Composite)
FROM TableName
WHERE PeriodDataTime BETWEEN @Date1 AND @Date2
GROUP BY DATEPART(qq, PeriodDataTime), DATEPART(yy, PeriodDataTime)

This should return the SUM of the Composite column for each quarter of each year between date1 and date2, one quarter per row. But if you have quarter between these dates, for which there is no data, you will not see it in the resultset. For that you might want to use a tally-table.

OS


Go to Top of Page
   

- Advertisement -