Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...

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

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)

declare @aid int
set @aid =1
select ename from #emp
where eid = (select case isnull(mid,0) when 0 then eid
else mid end mid
from #emp
where eid=@aid
)


select m.ename from #emp e
join #emp m on (m.eid=isnull(e.mid,e.eid))
where e.eid=1

Is This Answer Correct ?    0 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What are sub reports and how to create them?

137


What is difference between line feed ( ) and carriage return ( )?

879


How to divide query output into multiple groups with the group by clause in ms sql server?

1011


How can delete duplicate records in cte in sql server?

950


What is the default value of an integer data type in sql server 2005?

941


What is dimension table? : sql server analysis services, ssas

1001


What are four major operators that can be used to combine conditions on a where clause?

1024


I have a table Events Events containing cardno,time,id,name--each id has a cardno my requirement is every day each employee swipe the card several times i want to calculate first and last time of each card the output should be name 1 2 6 7 in out in out holiday holiday xxx 09:30 06:30 09:40 06:45 where 1,2...... are dates for example january 1,2, etc. 6 and 7 are saturday and sunday how it is posssible

2213


What are the new scripting capabilities of ssms? : sql server management studio

1039


What are functions in the sql server?

1187


Explain the use of keyword with encryption. Create a store procedure with encryption?

933


What is TDS(Tabular Data Stream) Gateway?

121


How do indexes help, types?

937


How to provide column names in insert statements in ms sql server?

1129


What are the types of indexing?

1062