I’m trying to figure out a way to write a query that will pull records for the last 7 days from a log table. The query needs to return the date and the description. If there are no entries for a date, the query still needs to return that date in the results.
How do I go about creating a record for a day where there is nothing in the log file for that date?
Thanks,
crjunk
This is an example of the expected results:
10/29/2012, null
10/28/2012, null
10/27/2012, null
10/26/2012, "Error: Unable to load xyz."
10/25/2012, null
10/24/2012, null
10/23/2012, null
This is my way. Hope it helps you. A little explanation required I think, You should have the list of your dates as you already said so. Also you need to use LEFT OUTER JOIN to join the logs with the specific dates to have dates even if there was no records on that date. I used a little CTE thing to generate dates and created a sample table named
"Log"as you can see in the code below.Cheers