Click here to Skip to main content
15,891,704 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi frds

I have the following table

StaffId Level Id
-----------------------
M1 M1
s1 M1
s2 M1
s3 M1
s7 s1
s10 s7
s8 s5
a k


result
-----------

input : M1

output:

M1 M1
s1 M1
s2 M1
s3 M1
s7 s1
s10 s7

please reply ....
Posted
Comments
Ganesan Senthilvel 3-May-12 12:48pm    
Is it your academic exercise?
Sandeep Mewara 4-May-12 2:25am    
And the issue is?

1 solution

SQL
with CTE_List as
(
    select * from YourTable t where t.StaffId = @M1
    union all
    select * from CTE_List p, YourTable t where t.LevelId = p.StaffId
)
select * from CTE_List

@M1 is your input variable.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900