Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
shajimanjeri
Posting Yak Master
179 Posts |
Posted - 2010-06-21 : 04:42:54
|
| I have a table with name Users with 5 fields. Id (int), UserPF (varchar), UserName (varchar), ManagerPF (varhcar), ManagerName (varchar)Id ---- UserPF ---- UserName ---- ManagerPF ---- ManagerName 1 -------123 --------shaji---------456------------Alex2 -------786 --------Raheem--------456------------Alex3 -------456 --------Alex----------896------------Kudur4 -------896 --------Kudur---------900------------Riyalat5 -------900 --------Riyalat-------1000-----------MobyI used a hierarchy here to understand who are the managers of UserName :shaji.so,I want to write a query to get who are the managers of UserName: shajiFrom above table you can see that shaji manager is Alex and Alex manager is Kudur and Kudur manager is Riyalat and so on ...How to get a generalized query for this request Thanks in advance,regards |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2010-06-21 : 05:13:01
|
Use a recursive CTE (Common Table Expression). There are hundreds of examples on this site. N 56°04'39.26"E 12°55'05.63" |
 |
|
|
shajimanjeri
Posting Yak Master
179 Posts |
Posted - 2010-06-21 : 05:28:57
|
| Thanks Peso,But can you provide an example kindly with the data which I provided. Because I am not familiar with recursive CTEregards |
 |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2010-06-21 : 05:50:23
|
Well, then this is an excellent opportunity for you to learn something new!Or did you expect us to do your homework?See this topic for more learning about recursive CTEhttp://www.sqlteam.com/forums/topic.asp?TOPIC_ID=89335 N 56°04'39.26"E 12°55'05.63" |
 |
|
|
|
|
|