Sql Server 2005+中用公用表表达式(CTE)实现递归查询
来源:网络 责任编辑:栏目编辑 发表时间:2013-07-02 06:42 点击:次
源码:
DECLARE @ID int
SET @ID=1
WITH CTETest as
(
select * from TestRecursive WHERE ParentID=@ID
union all
SELECT a.* FROM TestRecursive a inner join CTETest b
on a.ParentID=b.ID
)
select * from CTETest
DECLARE @ID int
SET @ID=1
WITH CTETest as
(
select * from TestRecursive WHERE ParentID=@ID
union all
SELECT a.* FROM TestRecursive a inner join CTETest b
on a.ParentID=b.ID
)
select * from CTETest
相关新闻>>
最新推荐更多>>>
- 发表评论
-
- 最新评论 更多>>