Reputation: 39
I have a table which have 3 columns
An I want to split on each day based on Promo_Period_Start and Promo_Period_End
What I tried is the following
declare @d datetime;
set @d = getdate();
select *
from [dbo].[T]
where @d between Promo_Period_Start and Promo_Period_End
SAMPLE DATA
Upvotes: 1
Views: 5921
Reputation: 1651
Use a recursive CTE
;WITH cte AS (
SELECT ID, Promo_Period_Start,Promo_Period_End
FROM T
UNION ALL
SELECT ID, DATEADD(day, 1, Promo_Period_Start), Promo_Period_End
FROM cte
WHERE Promo_Period_Start < Promo_Period_End
)
SELECT * FROM cte
Upvotes: 1