BINARY_CHECKSUM#
Returns a checksum computed over one or more expressions. The function is variadic (one or more arguments), order-sensitive (changing the argument order changes the result) and deterministic (the same arguments in the same order always return the same value).
Syntax#
BINARY_CHECKSUM ( expression [ , expressionN ] )
Arguments#
expression
One or more expressions, evaluated and folded in the order given.
Return types#
int
Remarks#
BINARY_CHECKSUM folds character arguments case-sensitively, over their raw byte values —
unlike CHECKSUM, which case-folds strings. Trailing spaces are still ignored, matching
char/varchar comparison semantics, and an empty string contributes nothing to the result.
Querona hashes BINARY_CHECKSUM in its own engine, byte-exact with SQL Server, for a specific
argument subset: the integer family (bit, tinyint, smallint, int, bigint), ASCII
char/varchar, and binary/varbinary. Every other data type SQL Server’s
BINARY_CHECKSUM accepts — nvarchar/nchar, the date/time family,
decimal/numeric/money/smallmoney, float/real, uniqueidentifier and
sql_variant — cannot be hashed byte-exactly in the engine, so a query that uses one is
evaluated on a SQL Server data source, which computes it byte-exactly. This routing is automatic
and the returned value is unchanged; such a call fails only when no data source able to evaluate it
is available. text, ntext, image and xml arguments are invalid, as in SQL Server
(Msg 8116).
Note
Engine-local char/varchar hashing is byte-exact only for ASCII characters. A value
containing bytes above 127 raises the engine error; evaluate such values on a SQL Server data
source for an exact result.
Examples#
SELECT BINARY_CHECKSUM('a'); -- 97 (byte value of 'a')
SELECT BINARY_CHECKSUM('A'); -- 65 (case-sensitive, differs from 'a')
SELECT BINARY_CHECKSUM('a '); -- 97 (trailing space ignored)
SELECT BINARY_CHECKSUM(''); -- 0 (empty string contributes nothing)
-- Msg 8116: Argument data type xml is invalid for argument 1 of BINARY_CHECKSUM function.
SELECT BINARY_CHECKSUM(CAST('<a/>' AS xml));