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)
 sum between months

Author  Topic 

SCHEMA
Posting Yak Master

192 Posts

Posted - 2008-09-04 : 13:47:29
suppose i have query like this:

Select id,startdate,enddate,sum(days)
from table
group by id,startdate,enddate

How can i group by :datediff(month,startdate,enddate)=3

I want sum for quarterly(between startdate and enddate)
Thanks.

SCHEMA
Posting Yak Master

192 Posts

Posted - 2008-09-04 : 14:21:54
Anyone?
Go to Top of Page

Bustaz Kool
Master Smack Fu Yak Hacker

1834 Posts

Posted - 2008-09-04 : 14:22:07
Can you clarify your request? A date difference of three is a condition; not a value. Perhaps some sample data.

=======================================
It is impossible to imagine Goethe or Beethoven being good at billiards or golf. -H.L. Mencken, writer, editor, and critic (1880-1956)
Go to Top of Page

SCHEMA
Posting Yak Master

192 Posts

Posted - 2008-09-04 : 14:22:59
I want sum(days) to be group by quarterly.
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-09-04 : 14:27:36
quote:
Originally posted by SCHEMA

I want sum(days) to be group by quarterly.


do you meant this?
SELECT id,DATEADD(q,DATEDIFF(q,0,startdate),0),sum(days)
FROM table
GROUP BY id,DATEADD(q,DATEDIFF(q,0,startdate),0)
Go to Top of Page

SCHEMA
Posting Yak Master

192 Posts

Posted - 2008-09-04 : 14:33:20
Thanks Visakh!!! Great.
Go to Top of Page
   

- Advertisement -