;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 的递归写法

 

 posted on 2015-12-24 22:37  只争朝夕  阅读(249)  评论(0)    收藏  举报