Write a query to get FirstName in upper case as "First Name".
SELECT UPPER(FirstName) AS [First Name] FROM
EmployeeDetail
Write a query to get FirstName in lower case as "First Name".
SELECT lower(FirstName) AS [First Name] FROM EmployeeDetail
Write a query for combine FirstName and LastName and display
it as "Name" (also include white space between first name & last
name)
SELECT FirstName +' '+ LastName AS [Name] FROM
EmployeeDetail
Select employee detail whose name is "Vikas"
SELECT * FROM EmployeeDetail WHERE FirstName = 'Vikas'
Get all employee detail from EmployeeDetail table whose
"FirstName" start with latter 'a'.
SELECT * FROM EmployeeDetail WHERE FirstName like 'a%'
Get all employee details from EmployeeDetail table whose
"FirstName" contains 'k'
SELECT * FROM EmployeeDetail WHERE FirstName like '%k%'
9. Get all employee details from EmployeeDetail table whose
"FirstName" end with 'h'
ANS: SELECT * FROM EmployeeDetail WHERE FirstName like '%
h'
Questions Answers
11). Get all employee detail from EmployeeDetail table whose
"FirstName" not start with any single character between 'a-p'
Ans: SELECT * FROM [EmployeeDetail] WHERE FirstName like '[
^a-p]%'
13). Get all employee detail from EmployeeDetail table whose
"FirstName" start with 'A' and contain 5 letters.
Ans: SELECT * FROM [EmployeeDetail] WHERE FirstName like '
A____' --there are four "_"
14). Get all employee detail from EmployeeDetail table whose
"FirstName" containing '%'. ex:-"Vik%as".
Ans: SELECT * FROM [EmployeeDetail] WHERE FirstName like '
%[%]%'
--According to our table it would return 0 rows, because no name
containg '%'
15). Get all unique "Department" from EmployeeDetail table.
Ans: SELECT DISTINCT(Department) FROM [EmployeeDetail]
16). Get the highest "Salary" from EmployeeDetail table.
Ans: SELECT MAX(Salary) FROM [EmployeeDetail]
17). Get the lowest "Salary" from EmployeeDetail table.
Ans: SELECT MIN(Salary) FROM [EmployeeDetail]
***SQL SERVER DATE RELATED INTERVIEW QUERY***
18). Show "JoiningDate" in "dd mmm yyyy" format, ex- "15 Feb
2013"
Ans: SELECT CONVERT(VARCHAR(20),JoiningDate,106) FROM
[EmployeeDetail]
19). Show "JoiningDate" in "yyyy/mm/dd" format, ex-
"2013/02/15"
Ans: SELECT CONVERT(VARCHAR(20),JoiningDate,111) FROM
[EmployeeDetail]
20). Show only time part of the "JoiningDate".
Ans: SELECT CONVERT(VARCHAR(20),JoiningDate,108) FROM
[EmployeeDetail]
Related Tables:-
31. Select only one/top 1 record from "EmployeeDetail" table.
Ans: SELECT TOP 1 * FROM [EmployeeDetail]
32. Select all employee detail with First name "Vikas","Ashish",
and "Nikhil".
Ans: SELECT * FROM [EmployeeDetail] WHERE FirstName IN('V
ikas','Ashish','Nikhil')
33. Select all employee detail with First name not in
"Vikas","Ashish", and "Nikhil".
Ans: SELECT * FROM [EmployeeDetail] WHERE FirstName NOT
IN('Vikas','Ashish','Nikhil')
34. Select first name from "EmployeeDetail" table after removing
white spaces from right side
Ans: SELECT RTRIM(FirstName) AS [FirstName] FROM [Employe
eDetail]
35. Select first name from "EmployeeDetail" table after removing
white spaces from left side
Ans: SELECT LTRIM(FirstName) AS [FirstName] FROM [Employe
eDetail]
36. Display first name and Gender as M/F.(if male then M, if
Female then F)
Ans: SELECT FirstName, CASE WHEN Gender = 'Male' THEN 'M'
WHEN Gender = 'Female' THEN 'F' END AS [Gender]
FROM [EmployeeDetail]
37. Select first name from "EmployeeDetail" table prifixed with
"Hello "
Ans: SELECT 'Hello ' + FirstName FROM [EmployeeDetail]
38. Get employee details from "EmployeeDetail" table whose
Salary greater than 600000
Ans: SELECT * FROM [EmployeeDetail] WHERE Salary > 600000
39. Get employee details from "EmployeeDetail" table whose
Salary less than 700000
Ans: SELECT * FROM [EmployeeDetail] WHERE Salary < 700000
40. Get employee details from "EmployeeDetail" table whose
Salary between 500000 than 600000
Ans: SELECT * FROM [EmployeeDetail] WHERE Salary BETWEE
N 500000 AND 600000
41. Select second highest salary from "EmployeeDetail" table.
Ans: SELECT TOP 1 Salary FROM
(SELECT TOP 2 Salary FROM [EmployeeDetail] ORDER BY Salar
y DESC) T ORDER BY Salary ASC