Sql Server 2005+中用公用表表达式(CTE)实现递归查询
来源:未知 责任编辑:智问网络 发表时间:2013-09-02 11:44 点击:次
源码:
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
相关新闻>>
最新推荐更多>>>
- 发表评论
-
- 最新评论 更多>>