My table PRODUCT
has 3 columns:
Product_ID
INTRODUCED_DATE
WITHDRAWAL_DATE
I need to create a derived table PRODUCT_ALL_DATES
from this table that list all the dates that a Product was active.The Date ranges are INTRODUCED_DATE
(Start Date) and WITHDRAWAL_DATE
(End Date)
How can I achieve this in SQL Server?I have indicated the sample output in the attached image:
Thanks!
declare @dateh table(ind int identity(1,1),date1 smalldatetime,date2 smalldatetime)
insert into @dateh select '1/1/2011','1/15/2011'
select * from @dateh
;with T as
(
select date1,date2 from @dateh as d
union all
select dateadd(dd,1,date1),date2 From T
where dateadd(dd,1,date1)<= date2
)
Select date1 from T
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With