Home All Groups Group Topic Archive Search About

SQL Server returning hierarchical records

Author
21 Jul 2006 11:16 AM
archon
does SQL Server 2005 have something similar to Oracle's START WITH CONNECT
BY sql syntax, for returning hierarchical records?

Author
21 Jul 2006 11:23 AM
Dan Sullivan
Yes, look up recursive CTEs [SQL Server] in the BOL.
Author
21 Jul 2006 11:38 AM
Omnibuzz
Author
22 Jul 2006 3:38 PM
--CELKO--
>> does SQL Server 2005 have something similar to Oracle's START WITH CONNECT BY sql syntax, for returning hierarchical records? <<

The Oracle syntax is a hidden cursor; if you want to avoid good SQL
coding you can use an explicit cursor that does the same thing.

Get a copy of TREES & HIERARCHIES IN SQL for sevreal diffrent ways of
doing this.  The recursive CTE approach has a lot of overhead; Nested
sets is good for computations; enumerated path is good for locating
sub-tree structures; etc.

The real trick in all of these models is the (complicated) CHECK()
constraints needed to assure that you actually have a tree and not a
more general graph.

AddThis Social Bookmark Button