How can I generate a temporary table filled with dates in SQL Server 2000?

后端 未结 11 560
没有蜡笔的小新
没有蜡笔的小新 2020-11-30 05:21

I need to make a temporary table that holds of range of dates, as well as a couple of columns that hold placeholder values (0) for future use. The dates I need are the firs

11条回答
  •  忘掉有多难
    2020-11-30 06:00

    Create a table variable containing a date for each month in a year:

    declare @months table (reportMonth date, PRIMARY KEY (reportMonth));
    declare @start date = '2018', @month int = 0; -- base 0 month
    while (@offset < 12)
    begin
        insert into @reportMonths select dateAdd(month, @offset, @start);
        select @offset = @offset + 1; 
    end
    

提交回复
热议问题