Reputation: 41
How can i display a range of date in SQL Server if i have a start date and end date.
Like i have start date 1/1/2014 and end date as 1/30/2014
the output should be
1/1/2014
1/2/2014
....
29/1/2014
30/1/2014
Upvotes: 1
Views: 121
Reputation: 93694
Using CTE u can create dates. A recursive CTE
is one in which an initial CTE is repeatedly executed to return subsets of data until the complete result set is obtained to know more about RECURSIVE CTE
check here
with cte as
(select convert(datetime,'2014-01-01') dates
union all
select dateadd(dd,1,dates) from cte where dates < convert(datetime,'2014-01-30'))
select * from cte
Upvotes: 4