0% found this document useful (0 votes)
47 views

SQL SERVER Interview Question

This document contains several SQL queries: 1. An update query to change all male genders to female and vice versa in a single query using a CASE statement. 2. A query to find the maximum salary for each department from an Employee table grouped by department. 3. Queries to find employee names and counts between two dates, employees whose name starts with "M", records where deptno is 10 or 20, and more.

Uploaded by

Ajit More
Copyright
© © All Rights Reserved
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
47 views

SQL SERVER Interview Question

This document contains several SQL queries: 1. An update query to change all male genders to female and vice versa in a single query using a CASE statement. 2. A query to find the maximum salary for each department from an Employee table grouped by department. 3. Queries to find employee names and counts between two dates, employees whose name starts with "M", records where deptno is 10 or 20, and more.

Uploaded by

Ajit More
Copyright
© © All Rights Reserved
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 3

http://www.dotnetlearners.com/home.

aspx
http://www.msdotnet.co.in/search/label/Real%20Time%20Projects#.U2ir3vm!"o
http://code.da#pilot.or$/ta$/t%torial
http://www.entheosweb.com/website&desi$n/advanced&web&desi$n.asp
SQL SERVER Interview Question
Update employee gender male to female and female to male with single query using case statement
UPDATE tblEmployee SET Gender =(CASE WHEN Gender = 'F' THEN 'M' ELSE 'F' END)
Calculate the sum of SrNo from Name using table?
Eg.: Table: nfo
SrNo Name
! "
# "
$ %
& %
''''''''''''''''''
"ns: Name SrNo
" $
% (
ele!t d"t"n!t N#me $%m(SrNo) &rom 'n&o (ro%p by (N#me)
http://www.dotnetlearners.com/home.aspx
http://www.msdotnet.co.in/search/label/Real%20Time%20Projects#.U2ir3vm!"o
http://code.da#pilot.or$/ta$/t%torial
http://www.entheosweb.com/website&desi$n/advanced&web&desi$n.asp
1. Sql Query to find second highest salary of Employee.
ele!t MA)(S#l#ry) &rom Employee WHE*E S#l#ry N+T 'N (ele!t MA)(S#l#ry) &rom Employee ),
2. SQL Query to find Max Salary from each department.
SELECT Dept'D$ MA)(S#l#ry) F*+M Employee G*+UP -. Dept'D/
3.Write a SQL Query to print the name of distinct employee hose !"# is $eteen %1&%1&1'(% to
31&12&1')*.
SELECT D'ST'NCT EmpN#me F*+M Employee WHE*E D+- -ETWEEN 012312324516 AND 0723283249:6,
+. Write an SQL Query find num$er of employees according to gender hose !"# is $eteen
%1&%1&1'(% to 31&12&1')*.
SELECT C+UNT(;)$ e< &rom Employee WHE*E D+- -ETWEEN 01231232451 ' AND 0723283249:6 G*+UP
-. e<
*.Write an SQL Query to find employee hose Salary is equal or greater than 1%%%%.
SELECT EmpN#me F*+M Employee WHE*E S#l#ry==21111,
(. Write an SQL Query to find name of employee hose name Start ith ,M-
SELECT ; F*+M Employee WHE*E EmpN#me l">e 'M?',
). Select all record from emp ta$le here deptno .1% or +%.
ele!t ; &rom emp @Aere deptno=71 or deptno=21,
/. 0o to create a clone of another ta$le
Cre#te t#ble emp2 # ele!t ; &rom emp @Aere 2=8,
'.0o can 1 retri2e all records of emp1 those should not present in emp23
Sele!t ; &rom emp) M"n% (Sele!t ; &rom emp2
http://www.dotnetlearners.com/home.aspx
http://www.msdotnet.co.in/search/label/Real%20Time%20Projects#.U2ir3vm!"o
http://code.da#pilot.or$/ta$/t%torial
http://www.entheosweb.com/website&desi$n/advanced&web&desi$n.asp
1%.0o to fetch only common records from to ta$les emp and emp13
(Sele!t ; &rom emp) 'ntere!t (Sele!t ; &rom emp2)

You might also like