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 2005 Forums
 Transact-SQL (2005)
 Nested Set: SELECT whole tree hierarchically

Author  Topic 

marty1976
Starting Member

22 Posts

Posted - 2011-08-05 : 04:11:37
Well yeah, the subject says it all...
I have a table with a nested set structure and I need to export the tree hierarchically.
But I can't figure out (nor find on the internet) how to SELECT the whole tree and print it in hierarchical order.

Any ideas? I have the gut feeling that this needn't be difficult, but I can't grip it yet.
I also have a 'hierarchy' column in the set, IMHO this should be all I need, but as I'm just a beginner with SQL...
Any help appreciated :-)

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2011-08-05 : 04:17:49
use Recursive Queries Using Common Table Expressions


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

marty1976
Starting Member

22 Posts

Posted - 2011-08-05 : 04:27:49
Thank you, but as fas as I understand this does not apply as the different branches of my tree share the same hierarchy level.
But it seems to work for a single branch...
Go to Top of Page

marty1976
Starting Member

22 Posts

Posted - 2011-08-05 : 05:18:13
Easy: Just ORDER BY "Left" and make the hierarchy visible by indenting spaces in front of a field like:
SELECT SPACE(Hierarchy * 2) + Name,...
Go to Top of Page
   

- Advertisement -