SQL Flow Field Guide

GREATEST

Catalog support for SQL Server 2022 (16.x) and 2025 (17.x)

conditional or n-ary selection

What changes

Input
a condition or index and value list
Output or change
one of the inputs
Return type
Returns the data type with the highest precedence from the set of types passed to the function. For more information, see Data Type Precedence (Transact-SQL). If all arguments have the same data type

Syntax at a glance

GREATEST ( expression1 [ , ...expressionN ] )

Work example

Choose the largest nonnull value from several expressions in one row.

Cast mixed inputs to the intended common type and test the all-null case.

Check your work GREATEST follows type precedence and ignores null arguments unless every argument is null.

Open Microsoft Learn for full syntax, permissions, and details for your version.