Hi @Kenny Gua
If I understand correctly, what you need is a recursive query.
;with CTE as(
select * from ERT where ExpCode = 'ST'
union all
select A.* from ERT as A inner join CTE as B
on A.ExpCode = B.MapCode)
select * from CTE;
Since there is something in your description that confuses me, I'm not sure if this is what you want, and if that's not what you want, please comment.
Best regards,
Percy Tang
If the answer is the right solution, please click "Accept Answer". If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our Documentation to enable e-mail notifications if you want to receive the related email notification for this thread.