Calendar table in SQL

后端 未结 3 436
隐瞒了意图╮
隐瞒了意图╮ 2021-01-28 05:59

How to create a table that contains a single column of date data type, that consists of all days starting from Jan 1, 2000 until today in oracle SQL

3条回答
  •  我在风中等你
    2021-01-28 06:24

    As your question is not clear, I'm assuming you want like this.

    SQL server Platform.

    CREATE table mycalender
    (
    mydate date
    );
    
    declare @startdate as date = '2000-01-01'
    
    WHILE(@startdate!=DATEADD(D, 0, DATEDIFF(D, 0, GETDATE())))
    begin
    insert into mycalender VALUES(@startdate)
    set @startdate=dateadd(day,1,@startdate)
    end
    

提交回复
热议问题