List of SQL Query questions on Datetime


The following exercise will help you to improve your MS SQL server query skills effectively. I have used Microsoft SQL server 2008 R2 for the following demo

techstudy.org

Kindle Paperwhite High Resolution Display Tablet | Rs. 9999

So, before starting let's create and populate tblstudent and tblScholarship table using following script.


1
2
3
4
5
6
7
8
9
Create table tblStudent
(
	StudentId int,
	FirstName varchar(50),
	LastName varchar(50),
	Admission_fee int,
	Admission_date datetime,
	Branch varchar(50),
)

- tblstudent

StudentId FirstName LastName Admission_fee Admission_date Branch
1 John Smith 1000 2018-06-10 Computer Engineering
2 David Jones 1200 2018-06-20 Civil Engineering
3 Michael Johnson 900 2018-08-15 Chemical Engineering
4 Chris Lee 1500 2018-07-10 Electrical Engineering
5 Mike Brown 1600 2018-09-10 Mechanical Engineering
6 Lisa Smith 1800 2018-07-10 Computer Engineering
7 Mary Smith 1600 2018-06-11 Computer Engineering
  1. Write a Sql query get first name, admission year, admission month and admission date from tblStudent table
  2. Write a SQL query to get student details from tblStudent table whose admission year is "2016"
  3. Write a SQL query to get student details from tblStudent table whose admission date is after January 31st 2018
  4. Write a SQL query to get student details from tblStudent table whose admission date is before January 31st
  5. Write a SQL query to get student details from tblStudent table whose admission month is 'June'
  6. Write a SQL query to get admission date and time from tblStudent table
  7. Write a SQL query to get database date
  8. Write a SQL query to get only month part of admission date from tblStudent
  9. Write a SQL query to get only year part of admission date from tblStudent
  10. Write a SQL query to get all student details from tblStudent table whose admission date between '2016-01-01' and '2018-01-01'
  11. Write a SQL query to Get the first name, last name, current date, admission date and difference between current date and admission date in days
  12. Write a Query to get the first name, last name, current date, admission date and difference between current date and admission date in month
  13. Write a Query to get the first name, last name, current date, admission date and difference between current date and admission date in year
  14. Write a Query to get "AdmissionDate" in "dd mmm yyyy" format, ex- "06 May 2016"
  15. Write a Query to get "AdmissionDate" in "yyyy/mm/dd" format, ex- "2019/05/06"
  16. Write a Query to get no of students get admission with respect to year and month from tblStudent table
     




Related Topics



Responses




Popular Posts

Facebook

Founded in 2016, Tech Study passionately delivers stylish and dynamic innovative information to programmer and technology lovers. http://www.techstudy.org/.