sql - Is it possible to effect a join against a table of consecutive dates without having to maintain an actual table of consecutive dates? -
I have a table with dated record I want a query that will show the number of records for each date.
Not hard, just by a group, is not it? Sure.
But I also want to show such days where no record was there. In this case, I will need to constantly go against the one-column table of the date, because a group BY is not showing a date which does not exist.
Is there a better way to do this? Or do I have to prepare a date table, so that I can go against it?
For example, if you want all dates from January 1, 2009 to date, Can work:
DECLARE @ start date DATETIME, select @AAS datetime, @start = '2009-01-01', @and = detat () DECLARE @Dates TABLE (dt DATETIME) WHILE (@start & lt; @end) BEGIN INSERT @ Select Date @ Start SELECT @start = DATEADD (Day, 1, Start @) Select from End * Date to
@ Every day of the day will have a record @ from @ end.
Comments
Post a Comment