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
Is it ok to shrink transaction log?
Create a dts package to produce a text file using the ‘update statistics’ command for the tables in a database with obsolete statistics.
How to execute stored procedure and set temp table in sql server?
What are sql servers used for?
Name 3 of the features that the sql server built-in function loginproperty performs on standard logins? : sql server security
what is a schema in sql server 2005? : Sql server database administration
What is the difference between coalesce() & isnull()?
what method you can use to reduce the overhead of Reporting Services data sources?
Can you leave a union at any time?
What is page in sql server?
How can sql server instances be hidden? : sql server security
How can you find out how many rows returned in a cursor?
explain different types of constraints? : Sql server database administration
Name 3 ways to get an accurate count of the number of records in a table?
How to create new tables with "select ... Into" statements in ms sql server?