Dates between two dates

  • I don't know if there is a performance gain using the SS2005 method, but if running SS2000 (or any other) then this will work fairly well:

    declare @StartDate  DATETIME,
            @EndDate    DATETIME;
    
    select  @StartDate  = '1/1/2007',
            @EndDate    = '2/10/2007';
    
    select  DateAdd(dd, Zn, @StartDate) as ConsecutiveDates
    from    Utility.dbo.Tally
    where   Zn <= DateDiff(dd, @StartDate, @EndDate)

    My Tally table starts at zero, so if yours starts at one you will need to make the appropriate changes (which is why I start mine at zero 😎 ).

    Tomm Carr
    --
    Version Normal Form -- http://groups.google.com/group/vrdbms

Viewing post 16 (of 15 total)

You must be logged in to reply to this topic. Login to reply