sql递归,按照日期显示每天

--实例

declare @dt1 date
declare @dt2 date
set @dt1 = '2016-05-30'
set @dt2 = '2016-06-13 23:59:59';
WITH dates
as(
select @dt1 as dt
union all
select dateadd(day, 1, T1.dt) as dt from dates T1
where 1=1
and T1.dt < @dt2
)
SELECT * from dates


 

--================================

with cte as
(
select Id,Pid,DeptName,0 as lvl from Department
where Id = 2
union all
select d.Id,d.Pid,d.DeptName,lvl+1 from cte c inner join Department d
on c.Id = d.Pid
)
select * from cte

posted @ 2016-06-20 12:07  狼人666  阅读(372)  评论(0编辑  收藏  举报