你的位置:首页 > 数据库

[数据库]SQL SERVER 递归


SELECT Folder_ID ,Folder_Name ,Folder_ParentId FROM dbo. Folder
 

 
递归语句:
 
在此我们以ADO.NET为例,查询ADO.NET下的子节点:
WITH TempFolder(Folder_ID,Folder_Name,Folder_ParentId)as
 (
    SELECT Folder_ID , Folder_Name,Folder_ParentId FROM Folder WHERE  Folder_ID ='32784691-D1F8-433B-88E3-A35A032470B4'
    UNION ALL
    SELECT A. Folder_ID, A. Folder_Name,A .Folder_ParentId FROM Folder A ,TempFolder T
    where A. Folder_ParentId=T .Folder_ID
)
查询结果:
SELECT * FROM TempFolder