table:employee
EID ENAME MID(manager ids)
101 rama null
102 sita 101
103 siva 101
104 ganesh 103
. . .
. . .
for 103 ID the manager ID is 101(RAMA) and for 104 manager
is SIVA
if i give employee id (EID) you have to tell the manager for
that EID write query?
eample:if i give 102 .The query output should be manager for
102 ID that it should print RAMA as output
Answer Posted / soorai ganesh
create table emp (eid int, ename varchar(50),mid int)
insert into emp values(1,'Ganesh',null)
insert into emp values(2,'Ramesh',1)
insert into emp values(3,'Suresh',1)
insert into emp values(4,'Selvam',2)
insert into emp values(5,'Vignesh',3)
select * from emp
Declare @eid int
Set @eid = 4 -- Your Input ID here..
Select 'Manager For '+CONVERT(VARCHAR,emp2.eid)+' --> '+ emp1.ename
From emp emp1
Inner join emp emp2 on emp1.eid = emp2.mid and emp2.eid = @eid
| Is This Answer Correct ? | 4 Yes | 1 No |
Post New Answer View All Answers
How you can move data or databases between servers and databases in sql server?
What is the difference between char and varchar2 datatype in sql?
Your table has a large character field there are queries that use this field in their search clause what should you do?
what's the maximum size of a row? : Sql server database administration
Does partitioning help performance?
What are logical/boolean operations in ms sql server?
What is the purpose of grouping data in a report?
What are the different types of cursor?
what are acid properties? : Sql server database administration
What is the difference between a function and a stored procedure?
What are the database objects? : SQL Server Architecture
What are the basic features of a trigger in ms sql server?
Are there any preferred steps that need to be taken care of before starting the installation of sql server 2000?
What do you mean by stored techniques? How would we use it?
What is triggers and stored procedures?