Thanks mike01...I need to learn how CTE works. So, will be watching some youtube video and come back and look at your code. Got the SQL Fiddle to work. My ignorance of not know beforehand. Here are the codes. Thanks for your patience. By the way, I modified the schema to make things consistent.
Create table Sample (
Item int,
Part_Num varchar(6),
Replaced_Part_Num varchar(5),
Part_Noun varchar(30)
)
Insert into Sample
select 1 ,'PN501','PN401', 'PartName501' union
select 2 ,'PN502','PN402', 'PartName502' union
select 3 ,'PN503','PN403', 'PartName503' union
select 4 ,'PN401','PN301', 'PartName401' union
select 5 ,'PN3402','PN302', 'PartName3403' union
select 6 ,'PN403','PN303', 'PartName403' union
select 7 ,'PN2301','PN201', 'PartName2301' union
select 8 ,'PN302','PN202', 'PartName302' union
select 9 ,'PN303','PN203', 'PartName303' union
select 10 ,'PN201','PN101', 'PartName201' union
select 11 ,'PN202','PN102', 'PartName202' union
select 12 ,'PN203','PN103', 'PartName203' union
select 10 ,'PN101','NULL', 'PartName101' union
select 11 ,'PN102','NULL', 'PartName102' union
select 12 ,'PN103','NULL', 'PartName103'
;
Query 1:
with cte as
( SELECT
[S].[Item]
, [S].[Part_Num]
, [S].[Replaced_Part_Num]
, [S].[Part_Noun]
FROM
[Sample] AS [S]
WHERE
[S].[Replaced_Part_Num] = 'PN102'
union all
SELECT
[S].[Item]
, [S].[Part_Num]
, [S].[Replaced_Part_Num]
, [S].[Part_Noun]
FROM
[Sample] AS [S]
join cte c
on s.Replaced_Part_Num = c.Part_Num )
select * from cte
[Results][2]:
| Item | Part_Num | Replaced_Part_Num | Part_Noun |
|------|----------|-------------------|--------------|
| 11 | PN202 | PN102 | PartName202 |
| 8 | PN302 | PN202 | PartName302 |
| 5 | PN3402 | PN302 | PartName3403 |