DATETIME : SQL SERVER QUERIES INTERVIEW FOR EXPERIENCED 2-3 YEARS WITH EXAMPLE : SET-3

SQL DATETIME QUERIES INTERVIEW QUESTIONS WITH ANSWERS TOP 10 DATETIME RELATED INTERVIEW QUERIES If you think this set contain easy que...

SQL DATETIME QUERIES INTERVIEW QUESTIONS WITH ANSWERS
TOP 10 DATETIME RELATED INTERVIEW QUERIES
If you think this set contain easy question then you can start with Set 9 (tricky quries)and be continue.
This is the 3rd set(21-30) of SQL INTERVIEW QUERIES SET, This set is for experienced developers, it's containing datetime related interview question with answers, So test your sql skill by answers following queries by yourself first.
So lets take it as a SQL Queries Quiz

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]

Click on the following link for NEXT SET OF QUESTIONS:
CLICK HERE FOR NEST SET (MORE THAN 600 QUERIES)

Related

SQL INTERVIEW QUERY 667707749365044395

Post a comment

  1. question no. 21 and 22 is not showing the output. It is showing out of range value.

    ReplyDelete
    Replies
    1. Question no.21 Try this: SELECT DATEPART(YYYY,JoiningDate) FROM [EmployeeDetail]

      Question no.22 Try this: SELECT DATEPART(MM,JoiningDate) FROM [EmployeeDetail]

      Delete
  2. Can u share screen shot of ur result at ahlawat.vikas24@gmail

    ReplyDelete
  3. very nice...useful for beginners

    ReplyDelete
  4. #26: Column Name in results should be "Total Days" (not Months)

    ReplyDelete
  5. how to get three months before joining employee record

    ReplyDelete
  6. in employeedetail table how to insert joining date format...can any one answer..

    ReplyDelete
  7. select datediff(mm,joining_date,getdate()) from table_name where datediff(mm,joining_date,getdate()) < 3

    ReplyDelete
  8. In question 21 and 22, datepart function used as Datepart(YEAR, Joiningdate),Datepart(Month, Joiningdate). But month and Year can be used with DateName like Datename(Month, Joiningdate) and Datename(Year, Joiningdate). Datename returns string and datepart returns int.

    ReplyDelete

emo-but-icon

Follow Us

Recent

Comments

Donate

Side Ads

Text Widget

Connect Us

Sql Server 2017 Interview Questions
Sql Server Basic Interview Query Set-1
Sql Server Basic Interview Query Set-2
Sql Server Date-Time Interview Query SET-3
Sql Server Salary Interview Query SET-4
Sql Server Group By Interview Query SET-5
Sql Server Join Interview Query SET-6
Sql Server Tricky Join Interview Query SET-7
Sql Server DDL Interview Query SET-8
Small but very Tricky Sql Server Query SET-9
Very Much Tricky Query (not 4 fresher)SET-10
Sql Server Complex Interview Query SET-11
Sql Server Datatype Interview Questions
Sql Server View Interview Questions
Sql Server Index Interview Questions
TCS Tricky Sql Interview Queries
HCL Sql Interview Queries
Sql Server SP Interview Questions
Sql Server Trigger Interview Questions
Sql Server Temp Table Interview Questions
Sql Server 2016 Interview Questions
Sql Server Performance Tuning Interview Q.
Sql Server Constraints Interview Questions
Sql Server Storage/Size Interview Questions
Sql Server Very Basic Interview Questions
Sql Server Quiz for Fresher
Sql Server Icon Quiz for All
Sql Server 300+ Theoretical Interview Questions
Sql Server Complete Set

ASP.NET AND JQUERY INTERVIEW QUESTION
ASP.NET: Web Config Interview Question
ASP.NET: View State Interview Question
ASP.NET: Session Interview Question
ASP.NET: Session Interview Question 
ASP.NET: Security Interview Question
ASP.NET: Catching Interview Question
C# OOPS Interview Question
MORE Interview Question
JQUERY: Interview Question Set-1
JQUERY: Interview Question Set-2
JAVA-SCRIPT: Interview Question Set-1
JAVA-SCRIPT: Interview Question Set-2
ASP.NET MVC: Interview Question Set-1

POPULAR POSTS
10 MOST DIFFICULT INTERVIEW QUESTIONS
5 BEST INTERVIEW TIPS
YOUR 10 MISTAKE DURING INTERVIEW
2016 TOP 20 GROUP DISCUSSION TOPICS
HOW SQL PERFORMANCE AFFECTED BY DATATYPE
item