April 4th, 2012, 10:21 AM
Outer join on month/year
I have a query like
that returns something like this:
select datepart(yyyy, mydate), datepart (mm, mydate), sum(myvalue)
2011 1 5
2011 2 8
2011 3 4
2011 5 7
There are no records in the table for April (4), as you can see. Normally I would do an outer join on a table to make sure that I return a record like "2011 4 0" but I'm not sure how to accomplish this when there is no real table to join against. I don't want to use a temp table because I'd like it to be a "self-contained" query.
Discontent is the first necessity of progress. - Edison
April 4th, 2012, 05:48 PM
you really should consider using a numbers table
Originally Posted by mateoc15
seriously, you won't regret it
which range of years did you want to see?