Get a list of dates between two dates using a function

前端 未结 21 1080
天涯浪人
天涯浪人 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:40

    Answer is avialbe here How to list all dates between two dates

    Create Procedure SelectDates(@fromDate Date, @toDate Date)
    AS
    BEGIN
        SELECT DATEADD(DAY,number,@fromDate) [Date]
        FROM master..spt_values
        WHERE type = 'P'
        AND DATEADD(DAY,number,@fromDate) < @toDate
    
    END
    

提交回复
热议问题