Scalar expressions and SQL functions
Conditional expressions, NULL handling, text, numeric and temporal functions.
Conditional expressions
CASE produces a conditional expression in a projection or calculation. COALESCE selects the first non-NULL value; NULLIF returns NULL when its arguments are equal. Branches should retain consistent types to stabilize conversions. Missing-value substitution must reflect a business rule: replacing NULL with zero changes averages and counts.
Strings, NULL and conditions
Strings: LEN, LOWER, UPPER, LEFT, RIGHT, SUBSTRING, REPLACE, REVERSE, STUFF, TRIM, LTRIM, RTRIM, CHARINDEX, PATINDEX, CONCAT and DATALENGTH. SUBSTRING/CHARINDEX positions are 1-based; CHARINDEX returns 0 when not found. CONCAT treats NULL as empty text. DATALENGTH reports expression-type size, not necessarily JSON or compressed-file size.
COALESCE accepts replacement candidates; NULLIF returns NULL when arguments compare equal; ISNULL and IIF have their own syntax. Do not assume universal lazy evaluation or another engine’s implicit rules.
SELECT CONCAT(N'Bonjour ', N'Alice') AS message,
SUBSTRING(N'Octaviius', 1, 4) AS prefixe,
CHARINDEX(N'vi', N'Octaviius') AS position;Dates and numbers
Dates: GETDATE(), GETUTCDATE(), CURRENT_TIMESTAMP, SYSDATETIME(), SYSUTCDATETIME(), SYSDATETIMEOFFSET(), YEAR, MONTH, DAY, DATEADD, DATEDIFF, DATEDIFF_BIG, DATEPART, DATENAME, EOMONTH, DATEFROMPARTS, DATETRUNC and ISDATE. DATEADD/DATEPART take a recognized unit such as day, month or microsecond.
Numeric functions include ABS, ROUND, SIGN, CEILING, FLOOR, POWER, SQUARE, SQRT, PI, RAND, trigonometry, logarithms and exponentials. RAND uses Python random rather than SQL Server’s sequence. CHECKSUM/CHECKSUM_AGG use native typed CRC32/xor algorithms, not SQL Server checksums.
SELECT DATEADD(day, 1, CAST('2026-01-01' AS DATE)) AS lendemain,
EOMONTH(CAST('2026-02-01' AS DATE)) AS fin_mois,
ROUND(CAST('12.3456' AS DECIMAL(19,4)), 2) AS arrondi;FORMAT and STRING_SPLIT
FORMAT implements common numeric/date patterns for explicitly recognized cultures, not the full .NET formatter. Prefer typed transport for client calculations and FORMAT for display. STRING_SPLIT is a table function with a separator and optional ordinal argument. Correlated APPLY and STRING_AGG WITHIN GROUP are unsupported. OBJECT_ID covers current-database tables/views; QUOTENAME delimits valid identifiers and returns NULL for out-of-bounds input.
SELECT value FROM STRING_SPLIT(N'a,b,c', N',');FORMAT: supported cultures and patterns
Cultures: en-US, en-GB, fr-FR, fr-CA, de-DE, es-ES and pt-PT. Named months/weekdays are available only in English/French. Standard temporal patterns include d, D, s, o/O, t, T, g, G and u, plus common yyyy, MM, dd, HH, mm, ss, up to six f digits and K tokens. The u pattern may display a literal Z; it does not automatically convert a value to UTC.
Numeric patterns include N, F, C, P, D, X, E and G with optional precision up to 100 formatting digits; some #/0/grouping/decimal patterns are recognized. Unsupported patterns fail explicitly. Prefer typed DATE/DATETIMEOFFSET for interchange and formatting only for presentation.
Inventory and signatures
The inventory provides signatures and arity for scalar functions, aggregates and syntactic functions. Arity describes argument count; each family’s contract specifies types, conversions and domain limits. Window functions have partition and frame semantics described in the analytical reference.
| Function | Signature | Arguments |
|---|---|---|
| ABS | ABS(expression) | Special syntax |
| ACOS | ACOS(arg1) | 1 |
| ASIN | ASIN(arg1) | 1 |
| ATAN | ATAN(arg1) | 1 |
| ATN2 | ATN2(arg1, arg2) | 2 |
| AVG | AVG([ALL|DISTINCT] expression) | Special syntax |
| CAST | CAST(expression AS type) | Special syntax |
| CEILING | CEILING(arg1) | 1 |
| CHARINDEX | CHARINDEX(arg1, arg2 [, …]) | 2..3 |
| CHECKSUM | CHECKSUM(arg1 [, …]) | 1..1000 |
| CHECKSUM_AGG | CHECKSUM_AGG([ALL|DISTINCT] expression) | Special syntax |
| COALESCE | COALESCE(a, b, …) | Special syntax |
| CONCAT | CONCAT(arg1, arg2 [, …]) | 2..254 |
| CONVERT | CONVERT(type, expression [, style]) | Special syntax |
| COS | COS(arg1) | 1 |
| COT | COT(arg1) | 1 |
| COUNT | COUNT(*) / COUNT([DISTINCT] expression) | Special syntax |
| COUNT_BIG | COUNT_BIG(*) / COUNT_BIG(expression) | Special syntax |
| CURRENT_TIMESTAMP | CURRENT_TIMESTAMP | Special syntax |
| DATALENGTH | DATALENGTH(arg1) | 1 |
| DATEADD | DATEADD(unit, amount, date) | 3 |
| DATEDIFF | DATEDIFF(unit, start, end) | 3 |
| DATEDIFF_BIG | DATEDIFF_BIG(unit, start, end) | 3 |
| DATEFROMPARTS | DATEFROMPARTS(arg1, arg2, arg3) | 3 |
| DATENAME | DATENAME(unit, date) | 2 |
| DATEPART | DATEPART(unit, date) | 2 |
| DATETRUNC | DATETRUNC(unit, date) | 2 |
| DAY | DAY(expression) | Special syntax |
| DEGREES | DEGREES(arg1) | 1 |
| DENSE_RANK | DENSE_RANK() OVER (…) | Special syntax |
| EOMONTH | EOMONTH(arg1 [, …]) | 1..2 |
| ERROR_LINE | ERROR_LINE() | 0 |
| ERROR_MESSAGE | ERROR_MESSAGE() | 0 |
| ERROR_NUMBER | ERROR_NUMBER() | 0 |
| ERROR_PROCEDURE | ERROR_PROCEDURE() | 0 |
| ERROR_SEVERITY | ERROR_SEVERITY() | 0 |
| ERROR_STATE | ERROR_STATE() | 0 |
| EXP | EXP(arg1) | 1 |
| FLOOR | FLOOR(arg1) | 1 |
| FORMAT | FORMAT(arg1, arg2 [, …]) | 2..3 |
| GETDATE | GETDATE() | Special syntax |
| GETUTCDATE | GETUTCDATE() | Special syntax |
| GROUPING | GROUPING(arg1) | 1 |
| GROUPING_ID | GROUPING_ID(arg1 [, …]) | 1..31 |
| IIF | IIF(arg1, arg2, arg3) | 3 |
| ISDATE | ISDATE(arg1) | 1 |
| ISNULL | ISNULL(value, replacement) | Special syntax |
| LAG | LAG(expression [, offset [, default]]) OVER (…) | Special syntax |
| LEAD | LEAD(expression [, offset [, default]]) OVER (…) | Special syntax |
| LEFT | LEFT(arg1, arg2) | 2 |
| LEN | LEN(expression) | Special syntax |
| LOG | LOG(arg1 [, …]) | 1..2 |
| LOG10 | LOG10(arg1) | 1 |
| LOWER | LOWER(expression) | Special syntax |
| LTRIM | LTRIM(arg1) | 1 |
| MAX | MAX([ALL|DISTINCT] expression) | Special syntax |
| MIN | MIN([ALL|DISTINCT] expression) | Special syntax |
| MONTH | MONTH(expression) | Special syntax |
| NTILE | NTILE(n) OVER (…) | Special syntax |
| NULLIF | NULLIF(a, b) | Special syntax |
| OBJECT_ID | OBJECT_ID(arg1 [, …]) | 1..2 |
| PATINDEX | PATINDEX(arg1, arg2) | 2 |
| PI | PI() | 0 |
| POWER | POWER(arg1, arg2) | 2 |
| QUOTENAME | QUOTENAME(arg1 [, …]) | 1..2 |
| RADIANS | RADIANS(arg1) | 1 |
| RAND | RAND( [, …]) | 0..1 |
| RANK | RANK() OVER (…) | Special syntax |
| REPLACE | REPLACE(arg1, arg2, arg3) | 3 |
| REVERSE | REVERSE(arg1) | 1 |
| RIGHT | RIGHT(arg1, arg2) | 2 |
| ROUND | ROUND(value, decimals) | Special syntax |
| ROW_NUMBER | ROW_NUMBER() OVER (…) | Special syntax |
| RTRIM | RTRIM(arg1) | 1 |
| SIGN | SIGN(arg1) | 1 |
| SIN | SIN(arg1) | 1 |
| SQRT | SQRT(arg1) | 1 |
| SQUARE | SQUARE(arg1) | 1 |
| STDEV | STDEV([ALL|DISTINCT] expression) | Special syntax |
| STDEVP | STDEVP([ALL|DISTINCT] expression) | Special syntax |
| STRING_AGG | STRING_AGG(expression, separator) | Special syntax |
| STRING_SPLIT | STRING_SPLIT(text, separator [, ordinal]) | Special syntax |
| STUFF | STUFF(arg1, arg2, arg3, arg4) | 4 |
| SUBSTRING | SUBSTRING(arg1, arg2, arg3) | 3 |
| SUM | SUM([ALL|DISTINCT] expression) | Special syntax |
| SYSDATETIME | SYSDATETIME() | 0 |
| SYSDATETIMEOFFSET | SYSDATETIMEOFFSET() | 0 |
| SYSUTCDATETIME | SYSUTCDATETIME() | 0 |
| TAN | TAN(arg1) | 1 |
| TRIM | TRIM(arg1 [, …]) | 1..2 |
| UPPER | UPPER(expression) | Special syntax |
| VAR | VAR([ALL|DISTINCT] expression) | Special syntax |
| VARP | VARP([ALL|DISTINCT] expression) | Special syntax |
| YEAR | YEAR(expression) | Special syntax |