Transact-SQL cheat sheet Posted on 2018-04-25 | Edited on 2024-07-16 | 1234567891011121314151617181920212223242526-- Get current datetimeGETDATE()-- Get year of datetimeYEAR(GETDATE())-- Get difference between datesDATEDIFF(dateformat, startdate, enddate)-- Subtract date, e.g.: DATEADD(HOUR, -11, GETDATE())DATEADD(Unit of time, value, date)-- Avalable Unit of time valueNANOSECOND, MICROSECOND, MILLISECOND, SECOND, MINUTE, HOUR, WEEKDAY, WEEK, DAY, DAYOFYEAR, MONTH, QUARTER, YEAR-- Betweenselect * from User where CreatedDate between '2016-09-26' and '2016-09-27'-- Order byselect * from User order by column desc-- Group byselect UserCode, Count(*) from User group by UserCode-- Select top 10SELECT TOP (10) * from User