首页 > 数据库技术 > 详细

T-SQL 递归算法实现

时间:2015-12-24 23:39:12      阅读:416      评论:0      收藏:0      [点我收藏+]

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

 

T-SQL 递归算法实现

原文:http://www.cnblogs.com/Scorpio05/p/5074534.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!