Hcl Technologies 3+ Experienced Sql server Questions

Answers were Sorted based on User's Feedback



Hcl Technologies 3+ Experienced Sql server Questions..

Answer / swapna

Hcl Placement Papers | Hcl Interview Procedure |
Hcl Aptitude Questions | Hcl Technical Questions
|Hcl Interview Questions


2 Tables will be there

Namely Employee having columns like Empid,Empname,Salary,Mgrid.

Phone Table having Empid and Phone number.

Based on these some questions like this

1) select all the Employees who does not have phone?

2)Dispaly all managers from table(Manager id is same as Empid)

3)How to know How many tables contain Empno as a column in database?

4)Find duplicate rows in a table or if we have table with one column which
has many records which are not distinct. How to find out the distinct
values from that column and number of times it's repeated?

5) How to delete the rows which are duplicate?(Don't remove both duplicate
records.)

6)How to find the 6th highest salary?

Hcl Placement Papers | Hcl Interview Procedure |
Hcl Aptitude Questions | Hcl Technical Questions
|Hcl Interview Questions

Is This Answer Correct ?    36 Yes 4 No

Hcl Technologies 3+ Experienced Sql server Questions..

Answer / raju

1 . select all the Employees who does not have phone?

Select e.Empid,e.Empname
From Employee e
left join Phone p
on p.empid = e.empid where p.phone is null

Is This Answer Correct ?    23 Yes 6 No

Hcl Technologies 3+ Experienced Sql server Questions..

Answer / chandrasekar

How to know How many tables contain Empno as a column in
database?

SELECT DISTINCT NAME FROM SYSOBJECTS WHERE ID IN (SELECT ID FROM SYSCOLUMNS WHERE NAME = 'EMPNO')

Is This Answer Correct ?    20 Yes 5 No

Hcl Technologies 3+ Experienced Sql server Questions..

Answer / suresh

6)How to find the 6th highest salary?

Select MIN(s.salary) FROM
(SELECT TOP 6 salary FROM Employee ORDER BY salary DESC)s

Is This Answer Correct ?    23 Yes 10 No

Hcl Technologies 3+ Experienced Sql server Questions..

Answer / babi

--1)select all the Employees who does not have phone?

SELECT * FROM EMPLOY WHERE EMPID NOT IN(SELECT EMPID FROM PHONE)


--2)Dispaly all managers from table(Manager id is same as Empid)

SELECT * FROM EMPLOY E WHERE E.EMPID=E.MGRID


--3)How to know How many tables contain Empno as a column in database?

SELECT name FROM sys.objects WHERE OBJECT_ID IN (SELECT object_id FROM sys.columns WHERE NAME like 'EMPNO')

--4)Find duplicate rows in a table or
-- if we have table with one column which has many records which are not distinct. How to find out the distinct values from that column and number of times its repeated


SELECT * FROM (
SELECT *,ROW_NUMBER()OVER(PARTITION BY EMPNAME ORDER BY EMPID ) AS NUMS FROM EMPLOY ) A WHERE NUMS>1

CREATE TABLE ONE(ID INT)
INSERT INTO ONE VALUES('1'),('2'),('3'),('4'),('5'),('1'),('2'),('3'),('4'),('5'),('1'),('2'),('3'),('4'),('5')
SELECT ID,COUNT(*) FROM ONE group by ID having COUNT(*)>1



--5) How to delete the rows which are duplicate?(Don't remove both duplicate records.)


WITH TA
AS
(
SELECT EMPID,EMPNAME,ROW_NUMBER() OVER(PARTITION BY EMPNAME ORDER BY SAL DESC ) AS Nums
FROM EMPLOY
)
DELETE FROM TA WHERE Nums>1

WITH AT
AS
(
SELECT *,ROW_NUMBER() OVER(PARTITION BY PHONENUMBER ORDER BY EMPID DESC)AS PHONENUMS FROM PHONE
)
DELETE FROM AT WHERE PHONENUMS>1

--6)how to Find 6th highest sal ?


SELECT MIN(SAL) FROM EMPLOY WHERE SAL IN(
SELECT DISTINCT TOP(6) SAL FROM EMPLOY ORDER BY SAL DESC
)
SELECT TOP 1 SAL FROM (SELECT DISTINCT TOP 6 SAL FROM EMPLOY ORDER BY SAL DESC) EMPLOY ORDER BY SAL

SELECT * FROM
( SELECT DISTINCT TOP 6 SAL , DENSE_RANK() OVER(ORDER BY SAL DESC ) AS RANKS FROM EMPLOY)
EMPLOY WHERE RANKS=6

Is This Answer Correct ?    7 Yes 1 No

Hcl Technologies 3+ Experienced Sql server Questions..

Answer / babi

--1)select all the Employees who does not have phone?

SELECT * FROM EMPLOY WHERE EMPID NOT IN(SELECT EMPID FROM PHONE)

Is This Answer Correct ?    10 Yes 4 No

Hcl Technologies 3+ Experienced Sql server Questions..

Answer / chandrasekar

SELECT COUNT(DISTINCT NAME)COUNT FROM SYSOBJECTS WHERE ID IN (SELECT ID FROM SYSCOLUMNS WHERE NAME = 'DEPOSITNO') AND NAME NOT LIKE 'SYNCOBJ%'

Is This Answer Correct ?    7 Yes 2 No

Hcl Technologies 3+ Experienced Sql server Questions..

Answer / susmita

2)Dispaly all managers from table(Manager id is same as
Empid)




select e.empname from tblemp as e where e.empid in (select distinct mgrid from tblemp)

Is This Answer Correct ?    5 Yes 0 No

Hcl Technologies 3+ Experienced Sql server Questions..

Answer / ramesh

How to find the 6th highest salary?

select top 1 salary from
(
select top 6 salary from employee order by salary desc
)a
order by salary

Is This Answer Correct ?    8 Yes 5 No

Hcl Technologies 3+ Experienced Sql server Questions..

Answer / vasumathi

3)How to know How many tables contain Empno as a column in
database?

select count(c.name) as Tables,c.name as Empno from
test.sys.tables as t inner join test.sys.columns as c on
c.object_id=t.object_id and c.name='Empno' group by c.name
having count (c.name) > 0

Is This Answer Correct ?    5 Yes 3 No

Post New Answer

More Placement Papers Interview Questions

Verifone PLACEMENT PAPERS ------ Verifone Placement Paper 1

1 Answers   Verifone,


INFOSYS PLACEMENT PAPERS ----- Placement Paper 1

1 Answers   Infosys,


how to be confident?

1 Answers  


Applabs Freshers Interview Paper ---- 24 Feb 2007

1 Answers   AppLabs,


TISL PLACEMENT PAPERS -------------- Placement Paper 3

1 Answers   TISL,






accenture

0 Answers   Accenture,


SNAPDEAL QUESTIONS 1. A train is going at a speed of 60kmph towards Delhi and returned back at a speed of 30kmph. What is its average speed? ANS : (2*30*60)/(30+60) = 40kmph 2. How many different 4 letter words can be framed that have at least one vowel? ANS : 264 - 214 (total no of 4 digits words – no of words with no vowels) 3. Write an algorithm to find out a number from an array of numbers where only one number occurs once and rest all occurs twice. ANS : XOR all the numbers ,you will get the number with single occurrences . 4. Which among the following have the product of the distance between opposite sides of a regular polygon and it side equals one fourth of the area. A. hexagon B. octagon C. n=16 D. n=18 ANS : n=16.(area of regular polygon = apothem*perimeter/2 Apothem = distance between opposite sides/2 Area = (opp_side_dist * n * a )/4 Product of opp_side_dist and side of reg. polygon = opp_side_dist * a For n= 16 the ration becomes 1:4 5. Which of the following cannot be a relation between two variables? ANS = 4th diagram. 6.what will be the output of this program Void print (int n) { If (n>0) { printf(“hello”); print(n-1); } printf(“world”); } ANS : N times hello followed by N+1 times world. 7. Which among the following cannot be used for future prediction? ANS : 4th Diagram. 8. There are 25 horses. We have to find out the fastest 3 horses In one race maximum 5 horses can run. How many such races are required in minimum to get the result. ANS : 7 races (A. first run all horses = 5 races, eliminate 4th 5th of all races. B. Run horses who came 1st in those 5 races = 1 race , the horse coming first is the fastest Run horses a. 2nd and 3rd with the fastest horse (in first time race A) b. 2nd and 3rd coming horse in B. c. The horse who came 2nd with the horse(who came 2nd in race B) in race A You will have the fastest 3 horses.) 9. In a game of rolling dice you are given 2 dice and you have to roll them. Whatever is the outcome the player will win that many dollars. What should the game owner charge each player (optimum) so that he doesn’t have to bear any loss? ANS : $7 10. We have a function REV(“string”,m,n).This function is capable of reversing the caharacters in the string from mth location to nth location. e.g. REV(“abcd”,2,3)  the output will be acbd We need to swap a string from a position,e.g. SWAP(“abcdefg”,4)  output needs to be efgabcd. How can the REV function used do this. ANS : L = string length,N= position given in SWAP function. SWAP(“abcdefg”,4) = REV(REV(REV(“abcdefg”,N+1,L),1,N),1,L).

1 Answers   SnapDeal,


what is bidirectional?

0 Answers  


Infosys Placement Paper Oct 1 5 2006 Hyderabad.

2 Answers   Infosys,


Learn T-SQL from SQL School

1 Answers   QualTech,


US TECHNOLOGY PLACEMENT PAPER

9 Answers   US Technology,


TATA ELXSI

2 Answers   TATA,


Categories