Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase ««12

Complex hierarchy: how to build? Expand / Collapse
Author
Message
Posted Tuesday, September 10, 2013 9:15 PM


SSC-Dedicated

SSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-Dedicated

Group: General Forum Members
Last Login: Yesterday @ 6:46 PM
Points: 36,944, Visits: 31,446
Dennis Post (9/10/2013)
Looks like a job for a recursive query.
Make up some sample data so we can help you out. (Create table + inserts + clean up)

Or you could check out the great SQLServerCentral articles and blogs on the subject.


I believe that it's actually a job for a simple splitter and a tiny bit of pair matching. If we can get a more clear example from the OP of even just one of these "hierarchical paths", this will be a simple job to convert to an Adjacency List "Orchard". From there, the sky is the limit because we can then slave it into a multi-tree orchard. The "Orchard" here is very similar a task I did in the past where I had to organize such data into an "Orchard" of hundreds of thousands of "Trees" all "living" on common "ground". Once it was converted to an Adjacency List, the next step was to convert it to Nested Sets and that's a whole lot easier and faster to do than it's ever been before (and, yes, it then uses an rCTE as part of the process). Please see the following article on that.
http://www.sqlservercentral.com/articles/Hierarchy/94040/


--Jeff Moden
"RBAR is pronounced "ree-bar" and is a "Modenism" for "Row-By-Agonizing-Row".

First step towards the paradigm shift of writing Set Based code:
Stop thinking about what you want to do to a row... think, instead, of what you want to do to a column."

(play on words) "Just because you CAN do something in T-SQL, doesn't mean you SHOULDN'T." --22 Aug 2013

Helpful Links:
How to post code problems
How to post performance problems
Post #1493429
Posted Wednesday, September 11, 2013 4:50 AM
SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-Enthusiastic

Group: General Forum Members
Last Login: Thursday, March 6, 2014 1:35 AM
Points: 178, Visits: 547
Thanks for the link Jeff.


Bit beyond me at the moment though.
I failed the "Who This Article Is For" section.
Never heard of Adjacency List or Nested Sets.

If / when I get involved with hierarchies, I know who's name to google.




For better, quicker answers on T-SQL questions, read Jeff Moden's suggestions.

"Million-to-one chances crop up nine times out of ten." ― Terry Pratchett, Mort
Post #1493568
« Prev Topic | Next Topic »

Add to briefcase ««12

Permissions Expand / Collapse