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 2008 Forums
 Transact-SQL (2008)
 fetching manager data

Author  Topic 

maulikk2000
Starting Member

3 Posts

Posted - 2011-03-07 : 06:40:27
Hi,

my question is, I've an employee table with three columns empid, empname and mgrid where employee can be a manager. I need to find all the employees who dont have a manager but who has atleast one employee assign to it..let me know how to achieve it

thanks,
Maulik

Lumbago
Norsk Yak Master

3271 Posts

Posted - 2011-03-07 : 06:48:13
Provide some CREATE TABLE scripts with some sample data and your expected output.

- Lumbago
My blog-> http://thefirstsql.com/2011/02/07/regular-expressions-advanced-string-matching-and-new-split-function-sql-server-2008-r2/
Go to Top of Page

maulikk2000
Starting Member

3 Posts

Posted - 2011-03-07 : 06:58:56
CREATE TABLE [dbo].[Employee](
[EmpId] [int] not NULL,
[MgrId] [int] NULL,
[EmpName] [varchar](50) not NULL
)

Sample data is


EmpId MgrId EmpName
1 NULL Test
2 NULL Test1
3 1 Test2
4 2 Test3
5 2 a

now expected result is
MgrID EmpName
1 Test
2 Test1

hope it makes sense..

thanks
Maulik
Go to Top of Page
   

- Advertisement -