;with a as(
select ID = 1
union all
select ID + 1 from a
where ID < 50
)
select *From a
OPTION (MAXRECURSION 0)
结果是50行连续的数字 option为无限制的写法,否则只能递归100次
;with a as (
select id form temp1 where id =#id
union all
select t1.id from a,temp1 t1
where t1.fatherid = a.id)
select * from a
OPTION (MAXRECURSION 0)
数据表中ID与FatherID 的递归写法
原文:http://www.cnblogs.com/Scorpio05/p/5074534.html