.
adhoc , :
declare @fromdate date = '20160101'
declare @thrudate date = '20171231'
;with n as (select n from (values(0),(1),(2),(3),(4),(5),(6),(7),(8),(9)) t(n))
, dates as (
select top (datediff(day, @fromdate, @thrudate)+1)
[Date]=convert(date,dateadd(day,row_number() over(order by (select 1))-1,@fromdate))
from n as deka cross join n as hecto cross join n as kilo
cross join n as tenK cross join n as hundredK
order by [Date]
)
select t.Name, d.Date, t.Id
from t
inner join dates d
on d.date >= t.arrdate
and d.date <= t.depdate
: http://rextester.com/WCM12325
:
+------+------------+-----+
| Name | Date | Id |
+------+------------+-----+
| A | 2016-03-29 | 100 |
| A | 2016-03-30 | 100 |
| A | 2016-03-31 | 100 |
| A | 2016-04-01 | 100 |
| A | 2016-04-02 | 100 |
| B | 2016-05-10 | 250 |
| B | 2016-05-11 | 250 |
| B | 2016-05-12 | 250 |
+------+------------+-----+
152 30- :
declare @fromdate date = '20000101';
declare @years int = 30;
;with n as (select n from (values(0),(1),(2),(3),(4),(5),(6),(7),(8),(9)) t(n))
select top (datediff(day, @fromdate,dateadd(year,@years,@fromdate)))
[Date]=convert(date,dateadd(day,row_number() over(order by (select 1))-1,@fromdate))
into dbo.Dates
from n as deka cross join n as hecto cross join n as kilo
cross join n as tenK cross join n as hundredK
order by [Date];
create unique clustered index ix_dbo_Dates_date on dbo.Dates([Date]);
select t.Name, d.Date, t.Id
from t
inner join dates d
on d.date >= t.arrdate
and d.date <= t.depdate
: http://rextester.com/WCM12325
:
+------+------------+-----+
| Name | Date | Id |
+------+------------+-----+
| A | 2016-03-29 | 100 |
| A | 2016-03-30 | 100 |
| A | 2016-03-31 | 100 |
| A | 2016-04-01 | 100 |
| A | 2016-04-02 | 100 |
| B | 2016-05-10 | 250 |
| B | 2016-05-11 | 250 |
| B | 2016-05-12 | 250 |
+------+------------+-----+
: