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.
| Author |
Topic |
|
jj7353
Starting Member
10 Posts |
Posted - 2004-12-14 : 09:25:08
|
| Hi sqlteam ...Seventhnight was so kind to provide me assistance for my last delima with deriving "rolling totals". I am using the query Seventhnight provided me.Select A.LOC, A.INSTALLED_MONTH, A.INSTALLED_CNT, TOTAL_SINCE_BEGINNING = sum(B.INSTALLED_CNT)From yourTable ACross Join yourTable BOn A.LOC = B.LOC and A.INSTALLED_MONTH >= B.INSTALLED_MONTHGroup By A.LOC, A.INSTALLED_MONTH, A.INSTALLED_CNTI have another delima with this same data I need solved. I need to provide every month from day one in my table. Before, if not all months were included as you can see below in my table. Here is another example of what my results need to look like:LOC |INSTALLED_MONTH|INSTALLED_CNT|TOTAL_SINCE_BEGINNINGZZZZZ |1/1/2004 |2 |2ZZZZZ |2/1/2004 |4 |6ZZZZZ|3/1/2004 |0 |6ZZZZZ |4/1/2004 |1 |7ZZZZZ |5/1/2004 |3 |10AAAA |1/1/2004 |1 |1AAAA |2/1/2004 |6 |7AAAA |3/1/2004 |1 |8Sorry about the look of this - I cannot seem to straigthen it out. I put some delimiters (|) in there. But notice the entry/row..."ZZZZ 3/1/2004 0 6". This is what I need my query to figure out and add it..the TOTAL_SINCE_BEGINNING counts from the previous month is carried over. I hope this makes sense.And thank you for any help.John |
|
|
AndrewMurphy
Master Smack Fu Yak Hacker
2916 Posts |
Posted - 2004-12-14 : 09:27:09
|
| looks like you need to 'cross join' to a master list of possible dates/months.Search here for 'cross join' + 'sequence number'....this is a small variation of other existing requirements. |
 |
|
|
|
|
|