ALLInterview.com :: Home Page KalAajKal.com
 Advertise your Business Here     
Browse  |   Placement Papers  |   Company  |   Code Snippets  |   Certifications  |   Visa Questions
Post Question  |   Post Answer  |   My Panel  |   Search  |   Articles  |   Topics  |   ERRORS new
   Refer this Site  Refer This Site to Your Friends  Site Map  Bookmark this Site  Set it as your HomePage  Contact Us     Login  |  Sign Up                      
info       Did you received any Funny E-Mails from your Friends and like to share with rest of our friends? Yeah!! you can post that stuff   HERE
Google
 
Categories  >>  Software  >>  Databases  >>  SQL Server
 
 


 

 
 Oracle interview questions  Oracle Interview Questions
 SQL Server interview questions  SQL Server Interview Questions
 MS Access interview questions  MS Access Interview Questions
 MySQL interview questions  MySQL Interview Questions
 Postgre interview questions  Postgre Interview Questions
 Sybase interview questions  Sybase Interview Questions
 DB Architecture interview questions  DB Architecture Interview Questions
 DB Administration interview questions  DB Administration Interview Questions
 DB Development interview questions  DB Development Interview Questions
 SQL PLSQL interview questions  SQL PLSQL Interview Questions
 Databases AllOther interview questions  Databases AllOther Interview Questions
Question
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
 Question Submitted By :: Om Namo Bhagavathe Vasudevaya
I also faced this Question!!     Rank Answer Posted By  
 
  Re: 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
# 1
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 ?    2 Yes 1 No
Soorai Ganesh
 
  Re: 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
# 2
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 2 No
Mohana Krishna
 
 
 
  Re: 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
# 3
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
Mohana Krishna
 
  Re: 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
# 4
Declare @eid int
Set @eid=2

select 'The manager for employee id '+convert(varchar
(50),e2.eid)+' is '+e1.ename from emp e1,emp e2
where e1.eid=e2.mid and e2.eid=@eid
 
Is This Answer Correct ?    1 Yes 0 No
Saravanan P
 
  Re: 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
# 5
-- create table #Employees (EID int, EName varchar(20), MID 
int)
-- insert #Employees values(101,'Rama',NULL)
-- insert #Employees values(102,'Sita',101)
-- insert #Employees values(103,'Shiva',101)
-- insert #Employees values(104,'Ganesh',103)

--for 103 ID the manager ID is 101(RAMA) and for 104 
manager is SIVA
--Write a script which displays Shiva's Manager's name.

select a.EID, a.EName, a.MID, b.EName
from #Employees a
inner join #Employees b on a.mid=b.eid and a.EName='Shiva'
 
Is This Answer Correct ?    1 Yes 0 No
Suraj
 

 
 
 
Other SQL Server Interview Questions
 
  Question Asked @ Answers
 
What is the difference between OLEDB and ODBC CFCI3
What are statistics, under what circumstances they go out of date, how do you update them? HCL2
Using query analyzer, name 3 ways you can get an accurate count of the number of records in a table? eFunds5
What are the steps you will take, if you are tasked with securing an SQL Server? HCL1
how to count datewise data in sqlserver IndusInd-Bank3
one table has four field id,name,design,salary. i have to find maximum salary .  6
What is the difference between temp table and table variable? Microsoft4
Which virtual table does a trigger use?  3
please can anyone answer this query Table 1 has 2 columns: EmployeeId,Age Table 2 has 2 columns: EmployeeId, Region Write SQL to Find the region who has the oldest person  7
There is table like Events...in that name ,startdate ,enddate,location are the column names write a stored Procedure for this table to get events by Months "GetEventsByMonths"  1
write down the code for "how we delete a table without using of Drop command " ? Sonata2
how to dispaly a particular row details from a given table  1
hi, may i know what is the command to get abstract the current month, current year and current day from a given date.i want these three in a isolated way..seperatedly is that any way in sql server 2000  3
how to replace double quotes by single quotes in sql server CAC2
Difference between Function and Procedure-in general?  3
i want table name basis on column name.  5
What is the STUFF function and how does it differ from the REPLACE function?  2
What is database normalization? Digicel5
What is the use of CASCADE CONSTRAINTS?  2
which query u can write to sql server doesn't work inbetween 7.00PM to nextday 9.00AM Wipro4
 
For more SQL Server Interview Questions Click Here 
 
 
 
 
 
   
Copyright Policy  |  Terms of Service  |  Help  |  Site Map 1  |  Articles  |  Site Map  |   Site Map  |  Contact Us interview questions urls   External Links 
   
Copyright © 2007  ALLInterview.com.  All Rights Reserved.

ALLInterview.com   ::  Forum9.com   ::  KalAajKal.com