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.

 All Forums
 SQL Server 2000 Forums
 Transact-SQL (2000)
 Please solve My Problem

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 managers
there can be a hierachy and there cannot be , my problem is to retrive Fnames from above table which are assigned some mannager .,for example
If @MgrId=6 then the result sould be sunny

NOte :-- there cana be a situation of a 2 or more level hierachy for example
if @MgrId=3 then the result sould be Deepika,Sandeep,Shanti also their nested values ie jaswinder,Vikas,Alex,Meenu,Chavi,Sahil,ashish ,Arvind

ie it should check for all the nested data within the same table.

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2007-04-23 : 05:00:41
Dupe
http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=82482


Peter Larsson
Helsingborg, Sweden
Go to Top of Page

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.
Go to Top of Page

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 @tt
select 1,'Deepika', 3 union
select 2,'Jaswinder', 1 union
select 3,'Manoj', 2 union
select 4,'Vikas', 1 union
select 5,'Alex', 1 union
select 6,'Sandeep', 3 union
select 7,'Shanti', 3 union
select 8,'Meenu', 1 union
select 9,'Chavi', 1 union
select 10, 'Sahil', 1 union
select 11, 'Ashish', 1 union
select 12 ,'Arvind', 1 union
select 13 ,'Sunny', 6
declare @mgr_id int
Select @mgr_id = 3
Select Fname from @tt where MgrId in (select Staff_ID from @tt where MgrId = @mgr_id) or mgrid = @mgr_id
Go to Top of Page

blindman
Master Smack Fu Yak Hacker

2365 Posts

Posted - 2007-04-23 : 08:56:33
Try this method: http://sqlblindman.googlepages.com/returningchildrecords

e4 d5 xd5 Nf6
Go to Top of Page
   

- Advertisement -