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
 Transact-SQL (2000)
 Query question

Author  Topic 

dcarva
Posting Yak Master

140 Posts

Posted - 2006-10-06 : 14:10:42
Hello,

I have a table (simplified) as follows:

Id Name ParentId
0 Support -1
1 Level 3 0
2 Services 1

So the full path looks like this based on parentid:

Support\Level3\Services

Question: what would the SELECT statement look like to return "Support\Level3\Services"? I can accomplish this using a cursor or temp table, but I want to avoid doing.

Thanks for any help in advance,
Danny

blindman
Master Smack Fu Yak Hacker

2365 Posts

Posted - 2006-10-06 : 14:35:12
Avoid the cursor, use the temp table.

You could do this by referencing the table three times, linked in a chain, but then you are hard-coding to always use three levels, and that is not good programming.

"Once you establish possibility, all that remains are desire and determination."
Go to Top of Page

chiragkhabaria
Master Smack Fu Yak Hacker

1907 Posts

Posted - 2006-10-07 : 01:59:48
check if this query helps you

http://www.nigelrivett.net/RetrieveTreeHierarchy.html

Chirag
Go to Top of Page

dcarva
Posting Yak Master

140 Posts

Posted - 2006-10-09 : 09:57:26
Thanks to all for your help. I ended up using something similar to what was posted, but I used table variables instead.

Thanks
Danny
Go to Top of Page
   

- Advertisement -