[Solved] How to find dates between two dates in SQL Server 2005


This will work in sqlserver 2005:

DECLARE @startdate datetime 

DECLARE @enddate datetime

SELECT @startdate="2015-12-04", @enddate="2015-12-07"

;WITH N(N)AS 
(SELECT 1 FROM(SELECT 1 UNION ALL SELECT 1 UNION ALL SELECT 1 UNION ALL SELECT 1)M(N)),
tally(N)AS(SELECT ROW_NUMBER()OVER(ORDER BY N.N)FROM N,N a,N b,N c,N d,N e,N f)
SELECT top (datediff(d, @startdate, @enddate) + 1) 
  dateadd(d, N - 1, @startdate)
FROM tally

Result(I removed timepart):

2015-12-04
2015-12-05
2015-12-06
2015-12-07

1

solved How to find dates between two dates in SQL Server 2005