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 / mohana krishna
select ename from employee
where eid = (select case mid when null then aid
else mid end mid
where eid=@aid
)
select m.name from employee e
join employee m on (m.aid=e.mid)
| Is This Answer Correct ? | 0 Yes | 3 No |
Post New Answer View All Answers
What to perform pattern match with the like operator?
What are the joins in sql server? : sql server database administration
How to connect Azure federated root database and apply federation in entity framework?
What are temporal tables in sql server 2016?
What are cursors stored procedures and triggers?
What is the stuff and how does it differ from the replace function?
What are “phantom rows”?
Can primary key be null?
application server is slow what may be the problem
How to check table values in sql server?
Can we use where and having clause together?
How to verify a login name with sqlcmd tool?
How to insert and update data into a table with "insert" and "update" statements?
Explain filestream storage of sql server 2008?
What are the benefits of normalization?