Basics

Batch Separators

  • Batch Separators combine one or more SQL statements that are sent to the engine as one set of statements.

  • Any variable declared in the current batch will not be visible in the next batch.

GO

Variables

DECLARE @variable_name data_type = value

Functions

String Functions

SUBSTRING()

REPLACE()

Mathematical Functions

ROUND()

CIEL()

Date Functions

Function

ISDATE()

validates date and time

GETDATE()

return current date and time

DATEFROMPARTS()

requires year, month and day

DATETIMEFROMPARTS()

requires year, month, day along with hour, minute, second, millisecond

DATEADD()

can add/subract to/from date and time

EOMONTH()

returns the last date of the specified month EOMONTH(GETDATE())

DATEDIFF()

returns the difference between the specified dates

DATENAME()DATEPART()

SELECT DATENAME(MONTH, GETDATE())

SELECT DATEPART(MONTH, GETDATE())

Output

February (Name of the Month)

Output

2 (Numerical representation of the month)

Window Functions

window_function( [ ALL ] expression )
OVER ( [ PARTITION BY partition_list ] [ ORDER BY order_list ] );
  • Value Window Functions FIRST_VALUE(), LAG(), LAST_VALUE(), LEAD()

MERGE

Last updated