0

I have a table that where each record has start and end dates. I need to return a record for each day between start and end date fields (including the start and end dates). Using MS SQL Server.

Example:

Current data

enter image description here

Data required:

enter image description here

Looking for recommendations. Thanks.

1 Answer 1

3

You can use recursive cte :

with cte as (
     select id, startdate, enddate, startdate as date
     from table t
     union all
     select id, startdate, enddate, dateadd(day, 1, date)
     from cte c
     where date < enddate
)
select *
from cte c
option (maxrecursion 0);
Sign up to request clarification or add additional context in comments.

1 Comment

This works well thank you, much appreciated.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.