Hi,
I have a challenge here that I'm sure there is a way around:
I'd like to create a trend query that has running totals per day (including days w/ 0 total). The only problem is that the table I am querying only has records for the days that events took place. e.g.
date total
10/08/2004 20
10/10/2004 15
10/14/2004 3
I would like to fill in the dates that were not there but I am strugging with finding a way to retrieve a set of days into a resultset.
I'd like my output to look like this
date total
10/07/2004 0
10/08/2004 20
10/09/2004 0
10/10/2004 15
etc etc
I've tried doing this with a WHILE statement & incrementing GETDATE()-@N but this results in multiple single record queries. Is there a systable that stores dates or a way to manipulate getdate to return something like the last N days in a column?
Once I have a way to retrieve the dates in this way, I should be able to create a right outer join on my table and replace the null totals with zeros using CASE.
I'd appreciate any help with this.
THANKS!
I have a challenge here that I'm sure there is a way around:
I'd like to create a trend query that has running totals per day (including days w/ 0 total). The only problem is that the table I am querying only has records for the days that events took place. e.g.
date total
10/08/2004 20
10/10/2004 15
10/14/2004 3
I would like to fill in the dates that were not there but I am strugging with finding a way to retrieve a set of days into a resultset.
I'd like my output to look like this
date total
10/07/2004 0
10/08/2004 20
10/09/2004 0
10/10/2004 15
etc etc
I've tried doing this with a WHILE statement & incrementing GETDATE()-@N but this results in multiple single record queries. Is there a systable that stores dates or a way to manipulate getdate to return something like the last N days in a column?
Once I have a way to retrieve the dates in this way, I should be able to create a right outer join on my table and replace the null totals with zeros using CASE.
I'd appreciate any help with this.
THANKS!