Please check this query:
;WITH CTE1 AS
(
SELECT * FROM #temp
UNPIVOT([Date] FOR [DateType] IN ([StartDate],[EndDate]))U
),CTE2 AS
(
SELECT Task,[Date]
FROM CTE1
WHERE [DateType]='StartDate'
UNION ALL
SELECT C2.Task,DATEADD(DAY,1,C2.Date)
FROM CTE2 C2 JOIN CTE1 C1 ON C2.Task=C1.Task AND C1.DateType = 'EndDate' AND C2.Date<C1.Date
)
SELECT * FROM CTE2
ORDER BY Task,[Date]
Output:
Best regards,
Cosmog Hong
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our Documentation to enable e-mail notifications if you want to receive the related email notification for this thread.