Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 Directory Structure

Author  Topic 

yan_er04
Starting Member

1 Post

Posted - 2005-11-21 : 03:21:59
Not sure whether this is possible in a single SQL. I'm using MS SQL 2000.

i have a tbl with a subFolderID (unique ID) and a parentID, the parentID basically refer to the same table (tells me the parent folder of that specific folder)

i want to retrieve the directory structure now... of a specific subFolderID... how do i do it?

the logic is something like using the subFolderID, find the parentID, using that as a subFolderID, find the parentID and so on...

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2005-11-21 : 03:53:55
http://vyaskn.tripod.com/hierarchies_in_sql_server_databases.htm
http://www.nigelrivett.net/RetrieveTreeHierarchy.html
http://www.seventhnight.com/treestructs.asp

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

surendrakalekar
Posting Yak Master

120 Posts

Posted - 2005-11-21 : 04:07:45
Using self join it is possible ... try this.
SELECT YT1.subFolderID, YT2.parentID, field1,field2....
FROM YourTable YT1 INNER JOIN YourTable YT2
ON YT1.subFolderID = YT2.parentID
WHERE (your conditions)
ORDER BY (sorting fields)

HTH


Surendra
Go to Top of Page
   

- Advertisement -