Get a list of dates between two dates using a function

前端 未结 21 1453
天涯浪人
天涯浪人 2020-11-22 06:25

My question is similar to this MySQL question, but intended for SQL Server:

Is there a function or a query that will return a list of days between two dates? For exa

21条回答
  •  青春惊慌失措
    2020-11-22 06:42

    I'm an oracle guy, but I believe MS SQL Server has support for the connect by clause:

    select  sysdate + level
    from    dual
    connect by level <= 10 ;
    

    The output is:

    SYSDATE+LEVEL
    05-SEP-09
    06-SEP-09
    07-SEP-09
    08-SEP-09
    09-SEP-09
    10-SEP-09
    11-SEP-09
    12-SEP-09
    13-SEP-09
    14-SEP-09
    

    Dual is just a 'dummy' table that comes with oracle (it contains 1 row and the word 'dummy' as the value of the single column).

提交回复
热议问题