troubleshooting Question

Recursive SQL Stored Procedure

Avatar of markej
markejFlag for United Kingdom of Great Britain and Northern Ireland asked on
Microsoft SQL ServerDatabases.NET Programming
9 Comments2 Solutions711 ViewsLast Modified:
I have a hierarchal data structure and the attached code will show a list of all the items linked to their parent. However I want to be able to 'walk' up the table as I will know the id I'm att BUT need to know the id's of it's parent etc upto the root.

Can someone help or explain how to do this. Thanks!
With Breadcrumb( id, parentid, description) as
	SELECT id, parentid, Description
	FROM   RadMenu
	--where  parentid IS NOT NULL
select parentid, id, description
from breadcrumb
order by parentid

Here's some of the data, filtered to show 1 example:

id      parentid Description
57	NULL	Adaptors
74	57	CompactFlash to IDE
75	57	CompactFlash to SATA
76	57	PCMCIA to CompactFlash
978	57	CFast to SATA
275	74	IDE to 1 CompactFlash Slot 
525	74	IDE to 2 CompactFlash Slots
555	74	IDE to 1 CompactFlash Slot

Open in new window

Join our community to see this answer!
Unlock 2 Answers and 9 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 2 Answers and 9 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros