Get a list of dates between two dates using a function

前端 未结 21 1101
天涯浪人
天涯浪人 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条回答
  •  -上瘾入骨i
    2020-11-22 06:47

    SELECT  dateadd(dd,DAYS,'2013-09-07 00:00:00') DATES
    INTO        #TEMP1
    FROM
    (SELECT TOP 365 colorder - 1 AS DAYS from master..syscolumns 
        WHERE id = -519536829 order by colorder) a
    
    WHERE datediff(dd,dateadd(dd,DAYS,'2013-09-07 00:00:00'),'2013-09-13 00:00:00' ) >= 0 
        AND  dateadd(dd,DAYS,'2013-09-07 00:00:00') <=  '2013-09-13 00:00:00'  
        SELECT * FROM #TEMP1
    

提交回复
热议问题