1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
-- Get current datetime
GETDATE()

-- Get year of datetime
YEAR(GETDATE())

-- Get difference between dates
DATEDIFF(dateformat, startdate, enddate)

-- Subtract date, e.g.: DATEADD(HOUR, -11, GETDATE())
DATEADD(Unit of time, value, date)

-- Avalable Unit of time value
NANOSECOND, MICROSECOND, MILLISECOND, SECOND, MINUTE, HOUR, WEEKDAY, WEEK, DAY, DAYOFYEAR, MONTH, QUARTER, YEAR

-- Between
select * from User where CreatedDate between '2016-09-26' and '2016-09-27'

-- Order by
select * from User order by column desc

-- Group by
select UserCode, Count(*) from User group by UserCode

-- Select top 10
SELECT TOP (10) * from User