max

Returns the maximum value in a column or expression.

Syntax

max(expression)

Parameters

Examples

Usage

  • You can use max with exact and approximate numeric, character, and datetime columns; you cannot use it with bit columns. With character columns, max finds the highest value in the collating sequence. max ignores null values. max implicitly converts char datatypes to varchar, and unichar datatypes to univarchar, stripping all trailing blanks.

  • unichar data is collated according to the default Unicode sort order.

  • max preserves the trailing zeros in varbinary data.

  • max returns a varbinary datatype from queries on binary data.

  • The SAP ASE server goes directly to the end of the index to find the last row for max when there is an index on the aggregated column, unless:
    • The expression not a column.

    • The column is not the first column of an index.

    • There is another aggregate in the query.

    • There is a group by or where clause.

See also:
  • compute, group by and having clauses, select, where clause in Reference Manual: Commands

  • For general information about aggregate functions, see Transact-SQL Users Guide.

Standards

ANSI SQL – Compliance level: Transact-SQL extension.

Permissions

Any user can execute max.

Related reference
avg
min