0% found this document useful (0 votes)
9 views6 pages

Set 4 & 5 Practice Sheet

Uploaded by

02shreyansh03.09
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views6 pages

Set 4 & 5 Practice Sheet

Uploaded by

02shreyansh03.09
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

Set-3: Sql Server Date-Time Interview Query

(Date Time related Queries)


Related Table:-

***SQL DATETIME RELATED QUERIES***


21). Get only Year part of "JoiningDate".
Ans: SELECT DATEPART(YEAR, JoiningDate) FROM [EmployeeDetail]

22). Get only Month part of "JoiningDate".


Ans: SELECT DATEPART(MONTH,JoiningDate) FROM [EmployeeDetail]

23). Get system date.


Ans: SELECT GETDATE()

24). Get UTC date.


Ans: SELECT GETUTCDATE()

25). Get the first name, current date, joiningdate and diff between current date and
joining date in months.
Ans: SELECT FirstName, GETDATE() [Current Date], JoiningDate,
DATEDIFF(MM,JoiningDate,GETDATE()) AS [Total Months] FROM [EmployeeDetail]

26). Get the first name, current date, joiningdate and diff between current date and
joining date in days.
Ans: SELECT FirstName, GETDATE() [Current Date], JoiningDate,
DATEDIFF(DD,JoiningDate,GETDATE()) AS [Total Months] FROM [EmployeeDetail]

27). Get all employee details from EmployeeDetail table whose joining year is 2013.
Ans: SELECT * FROM [EmployeeDetail] WHERE DATEPART(YYYY,JoiningDate) = '2013'

28). Get all employee details from EmployeeDetail table whose joining month is
Jan(1).
Ans: SELECT * FROM [EmployeeDetail] WHERE DATEPART(MM,JoiningDate) = '1'

29). Get all employee details from EmployeeDetail table whose joining date between
"2013-01-01" and "2013-12-01".
Ans: SELECT * FROM [EmployeeDetail] WHERE JoiningDate BETWEEN '2013-01-
01' AND '2013-12-01'

30). Get how many employee exist in "EmployeeDetail" table.


Ans: SELECT COUNT(*) FROM [EmployeeDetail]
Set-4: Sql Server Salary Interview Query (Salary
Related Queries)
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('Vikas','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 [EmployeeDetail]

35. Select first name from "EmployeeDetail" table after removing white spaces from
left side
Ans: SELECT LTRIM(FirstName) AS [FirstName] FROM [EmployeeDetail]

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 BETWEEN 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 Salary DESC) T ORDER BY Salar
yASC

You might also like