Are you looking for something like this:
WITH Supercessions (PartNo, PNPrior) AS
(
SELECT 'RTC5756','STC9191'
UNION ALL SELECT 'SFP500160','STC9191'
UNION ALL SELECT 'STC9191','STC2951'
UNION ALL SELECT 'STC3765','STC9191'
UNION ALL SELECT 'STC8572','STC9191'
UNION ALL SELECT 'STC9150','STC9191'
),
[Source] (PartNo, PartDesc, Price) AS
(
SELECT 'SFP500160','KIT BRAKE LINING',58.02
),
PartsHierarchy AS
(
SELECT n=1, OriginalPart=b.PartNo, a.PartNo, PNPrior, PartDesc, Price
FROM Supercessions a
JOIN [Source] b ON a.PartNo = b.PartNo
UNION ALL
SELECT n+1, OriginalPart, b.PartNo, b.PNPrior, PartDesc, Price
FROM PartsHierarchy a
JOIN Supercessions b ON a.PNPrior = b.Partno
)
SELECT *
FROM PartsHierarchy;
Note how I've set up your sample data for you in a consumable form. Forum posting etiquette suggests you should do this to help your helpers help you. I've been kind today.
My thought question: Have you ever been told that your query runs too fast?
My advice:
INDEXing a poor-performing query is like putting sugar on cat food. Yeah, it probably tastes better but are you sure you want to eat it?
The path of least resistance can be a slippery slope. Take care that fixing your fixes of fixes doesn't snowball and end up costing you more than fixing the root cause would have in the first place.
Need to UNPIVOT? Why not CROSS APPLY VALUES instead?[/url]
Since random numbers are too important to be left to chance, let's generate some![/url]
Learn to understand recursive CTEs by example.[/url]
[url url=http://www.sqlservercentral.com/articles/St