First time user?    |

#### Select chapter

Basics (2.papers)
Data Types (2.papers)
Table-designing (1.papers)
Queries-Commands (3.papers)
String functions (2.papers)
Subqueries (1.papers)
Joins (1.papers)
Constraints (1.papers)
Triggers (1.papers)
Hide

# sql interview questions and answers

Please read the below given table for solving questions from 1 to 10
eidfnamelnameagesalarydeptdoj
1rajeevsukla2312000.net23-Oct-11 12:00:00 AM
2sowmyakumari2319000db13-Nov-10 12:00:00 AM
3kishorekumar2736000android16-Oct-11 12:00:00 AM
4abimanyubiswal22nullandroid25-May-10 12:00:00 AM
5sonikumar2421800.net21-Jun-09 12:00:00 AM
6anu_singh2212000db23-Oct-10 12:00:00 AM
7_dineshmoh%anty2315000.net26-Aug-09 12:00:00 AM
8nischala_kumari2218000db19-Jul-08 12:00:00 AM
9gouravchourasia2420000android06-Oct-13 12:00:00 AM
Note: Assume table is present in a database named skillgun , the Schema name is dbo and the table name as Employees ;
1
`Which of the following queries is used to add 10 days and 6 months to the given date ( '10-05-2014')?`
1. `select dateadd(month,06,dateadd(DAY,10,'10-05-2014'))`
2. `select dateadd(06,month,dateadd(DAY,10,'10-05-2014'))`
3. `select dateadd(06,month,dateadd(10,day,'10-05-2014'))`
4. `None of the above.`
Share
2
`Which of the following queries is used to add 10 days 10 months and 10 years to the current date?`
1. `select dateadd(DAY,10,DATEADD(month,10,dateadd(10,year,getdate())))`
2. `select dateadd(DAY,10,DATEADD(month,10,dateadd(year,10,getdate())))`
3. `select dateadd(10,day,DATEADD(month,10,dateadd(year,10,getdate())))`
4. `None of the above.`
Share
3
`How to check whether a given year is leap year or not?`
1. ```declare @year int ;
set @year=year('10-10-2014') ;
if(@year/4=0 and @year/100<>0)
begin
if(@year%400=0)
begin
print 'year is a leap year '
end
end```
2. ```declare @year int ;
set @year=year('10-10-2014') ;
if(@year/4=0 and @year/100<>0)
begin
print 'year is a leap year '
end
if(@year%400=0)
begin
print 'year is a leap year '
end```
3. ```declare @year int ;
set @year=year('10-10-2014') ;
if(@year/4=0 && @year/100<>0)
begin
print 'year is a leap year '
end
else
begin
print 'year is a leap year '
end```
4. `None of the above.`
Share
4
`What is the use of datediff function in SQL?`
1. `datdiff function used for calculating difference between two dates in days , months and years.`
2. `datediff function used for calculating difference between two dates in days or months or years.`
3. `None of the above.`
Share
5
```Which of the following query display difference between given date ('10-3-2018') and the current date in number of days?
Note: assuming given date is future date.```
1. `select datediff(getdate(),'10-3-2018',day)`
2. `select datediff(getdate(),days,'10-3-2018')`
3. `select datediff(getdate(),day,'10-3-2018')`
4. `select datediff(day,getdate(),'10-3-2018')`
Share
6
```Which of the following query display difference between given date ('10-3-2018') and the current date in number of months?
Note: assuming given date is future date.```
1. `select datediff(getdate(),'10-3-2018',month)`
2. `select datediff(getdate(),months,'10-3-2018')`
3. `select datediff(getdate(),month,'10-3-2018')`
4. `select datediff(month,getdate(),'10-3-2018')`
Share
7
`Which of the following queries display the employees information in the descending order of their joining years?`
1. `select * from employees order by date(doj) ;`
2. `select * from employees order by year(doj) desc ;`
3. `select * from employees order by year(doj) ;`
4. `None of the above.`
Share
8
`Which of the following queries display the employees information in the descending order of their joining weekdays ( Monday,Tuesday etcâ€¦ ) ?`
1. `select * from employees order by datename(weekday,doj) desc`
2. `select * from employees order by date(weekday,doj) ;`
3. `select * from employees order by weekday(doj) desc`
4. `None of the above.`
Share
9
`Which of the following queries display employees full names who joined on Saturday?`
1. `select fname+lname as 'fullname' from employees where datename(weekday,doj)=='saturday'`
2. `select fname+lname as 'fullname' from employees where weekday(doj)='saturday'`
3. `select fname+lname as 'fullname' from employees where datename(weekday,doj)='saturday'`
4. `None of the above.`
`Which of the following queries display the sum of salaries of all the employees who joined in the year 2011?`
1. `select sum(salary) as 'total2011empssal' from employees where datename(year,doj)=2011`
2. `select sum(salary) as 'total2011empssal' from employees where year(doj)=2011`
3. `Both first and second option are correct.`
4. `None of the above.`