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)
 summation problem two

Author  Topic 

jeff06
Posting Yak Master

166 Posts

Posted - 2008-01-14 : 15:03:14

Lamprey helped me solve a summation problem last time thank!
http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=95164

I have a variation of the problem i can not find a way to solve please help

Problem

I have a table:
amount group startdate enddate
23 g1 12/1/2005 1/2/2006
36 g2 12/1/2005 12/20/2006
45 g1 12/8/2005 1/3/3007
87 g1 12/10/2005 12/26/3007
67 g1 12/6/2005 12/18/3007

---

---
the earliest start date is 12/1/2005 and latest enddate is 1/10/2006

I WANT TO GET sum of amount of each day from 12/1/2005 to 1/10/2006

the result should like
date group sumamount
12/1/2005 g1 2346
12/1/2005 g2 2823
12/2/2005 g1 3456
12/2/2005 g2 230

---
12/20/2005 g2 654
----

for 12/1/2005, g1 the sumamount is sum of amount for all records with startdate<12/1/2005 and enddate >12/1/2005 for g1
for 12/1/2005, g2 the sumamount is sum of amount for all records with startdate<12/1/2005 and enddate >12/1/2005 for g2


for 12/20/2005, g1 the sumamount is sum of amount for all records with startdate<12/20/2005 and enddate >12/20/2005 for g1
for 12/20/2005, g2 the sumamount is sum of amount for all records with startdate<12/20/2005 and enddate >12/20/2005 for g2

How can i have a query to do that?
Thank you very much for any suggestions
Jeff
   

- Advertisement -