我从一个类似于此的表开始:
Name | StartDate | EndDate
------------------------------------
Bob | 5/1/2017 | 5/3/2017
Jeff | 6/1/2017 | 6/1/2017
Bob | 7/8/2017 | 7/10/2017
我希望这样结束:
Name | Date
------------------------------------
Bob | 5/1/2017
Bob | 5/2/2017
Bob | 5/3/2017
Jeff | 6/1/2017
Bob | 7/8/2017
Bob | 7/9/2017
Bob | 7/10/2017
答案 0 :(得分:3)
一种简单的方法是递归CTE:
with cte as (
select name, StartDate, EndDate
from t
union all
select name, dateadd(day, 1, StartDate), EndDate
from cte
where StartDate < EndDate
)
select name, StartDate as dte
from cte;
如上所述,这可以使用大约100天。如果您需要更多内容,只需在查询末尾添加option (maxrecursion 0)
即可。