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 |
Jaswinder
Starting Member
8 Posts |
Posted - 2007-04-23 : 04:58:48
|
Staff_ID Fname MgrId 1 Deepika 3 2 Jaswinder 1 3 Manoj null 4 Vikas 1 5 Alex 1 6 Sandeep 3 7 Shanti 3 8 Meenu 1 9 Chavi 1 10 Sahil 1 11 Ashish 1 12 Arvind 1 13 Sunny 6 This table is created to maintain hierachy of managersthere can be a hierachy and there cannot be , my problem is to retrive Fnames from above table which are assigned some mannager .,for exampleIf @MgrId=6 then the result sould be sunnyNOte :-- there cana be a situation of a 2 or more level hierachy for exampleif @MgrId=3 then the result sould be Deepika,Sandeep,Shanti also their nested values ie jaswinder,Vikas,Alex,Meenu,Chavi,Sahil,ashish ,Arvindie it should check for all the nested data within the same table. |
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
|
Jaswinder
Starting Member
8 Posts |
Posted - 2007-04-23 : 05:47:56
|
but i need results as per the required input , i do not need hierachy rather simple results. |
 |
|
pbguy
Constraint Violating Yak Guru
319 Posts |
Posted - 2007-04-23 : 08:30:01
|
declare @tt table (Staff_ID int, Fname varchar(50), MgrId int)insert @ttselect 1,'Deepika', 3 unionselect 2,'Jaswinder', 1 unionselect 3,'Manoj', 2 unionselect 4,'Vikas', 1 unionselect 5,'Alex', 1 unionselect 6,'Sandeep', 3 unionselect 7,'Shanti', 3 unionselect 8,'Meenu', 1 unionselect 9,'Chavi', 1 unionselect 10, 'Sahil', 1 unionselect 11, 'Ashish', 1 unionselect 12 ,'Arvind', 1 unionselect 13 ,'Sunny', 6 declare @mgr_id intSelect @mgr_id = 3Select Fname from @tt where MgrId in (select Staff_ID from @tt where MgrId = @mgr_id) or mgrid = @mgr_id |
 |
|
blindman
Master Smack Fu Yak Hacker
2365 Posts |
|
|
|
|
|
|