日期:2014-05-17 浏览次数:20491 次
;WITH CTE AS
(
SELECT [FolderID],[ParentID],CAST([FolderID] AS VARCHAR)+'\' AS [FolderPath]
FROM [Folder] WHERE [FolderID]=28
UNION ALL
SELECT F.[FolderID],F.[ParentID],[FolderPath]+CAST(F.[FolderID] AS VARCHAR)+'\' FROM [Folder] AS F
INNER JOIN CTE ON F.[ParentID]=CTE.[FolderID]
)
SELECT * FROM CTE
;WITH CTE AS
(
SELECT [FolderID],[ParentID],CAST([FolderID] AS VARCHAR)+'\' AS [FolderPath]
FROM [Folder] WHERE [FolderID]=28
UNION ALL
SELECT F.[FolderID],F.[ParentID],CAST(F.[FolderID] AS VARCHAR)+'\' FROM [Folder] AS F
INNER JOIN CTE ON F.[ParentID]=CTE.[FolderID]
)
SELECT * FROM CTE
--試試以下:
;WITH CTE AS
(
SELECT [FolderID],[ParentID],CAST(CAST([FolderID] AS VARCHAR)+'\' AS VARCHAR) AS [FolderPath]
FROM [Folder] WHERE [FolderID]=28
UNION ALL
SELECT F.[FolderID],F.[ParentID],CAST([FolderPath]+CAST(F.[FolderID] AS VARCHAR)+'\' AS VARCHAR) FROM [Folder] AS F
INNER JOIN CTE ON F.[ParentID]=CTE.[FolderID]
)
SELECT * FROM CTE