• This example shows how to quickly populate a table with successive dates? Not really, it shows a pretty convoluted way of doing it, not quick. Any time there is a while loop in T-SQL script, such a script is probably not efficient because SELECT is already a loop, and any attempts to use the slow while loop instead of a native select typically lead to performance issues. How about using a simple select, i.e.

    declare @dtFrom datetime;

    declare @dtTo datetime;

    declare @diff int;

    select

    @dtFrom = '2010-01-01T00:00:00.000',

    @dtTo = '2010-12-31T00:00:00.000',

    @diff = datediff(day, @dtFrom, @dtTo) + 1;

    create table #Dates

    (

    [Date] datetime not null primary key

    );

    -- this happily inserts dates exactly between first and last date, no more and no less

    insert into #Dates

    select top (@diff)

    dateadd(day, row_number() over (order by [object_id]) - 1, @dtFrom)

    from sys.all_columns;

    select * from #Dates;

    drop table #Dates;

    Oleg