Well, I figured it out on my own. If anyone can think of a better way, let me know:First I created a function that would return the "Folder>Folder>Folder" format I needed for each folderCREATE FUNCTION dbo.GetPath (@folderid int) RETURNS nvarchar(2000)ASBEGINDECLARE @Control bitDECLARE @ParentID intDECLARE @Path nvarchar(2000)SET @Path = ''SET @ParentID = @folderidSET @Control = 0WHILE @Control = 0 BEGIN SELECT @Path = FolderName + '>' + @Path, @ParentID = ParentID FROM WS_Folders WHERE FolderID = @folderid SET @folderid = @ParentID IF @folderid = 0 BEGIN SET @Control = 1 ENDEND -- remove trailing '>'RETURN LEFT(@Path, LEN(@Path) - 1)END
Then a simple query to return the results for the project:SELECT A.FolderName, A.FolderID FROM (SELECT dbo.GetPath(FolderID) AS FolderName, FolderID FROM WS_Folders WHERE ProjectID = 180) AS AORDER BY A.FolderName
And the output looks like this:Project Documents 7963Project Documents>Documents 7940Project Documents>Documents>Architecture and Engineering 7978etc...
Like I said, any ideas as to how this can be improved would be greatly appreciated.Brooks Williams