Home > OS >  Operand data type numeric is invalid for '~' operator
Operand data type numeric is invalid for '~' operator

Time:10-11

~ operator is not working for BIGINT datatype,

UPDATE Table
SET attrEx= attrEx & (~576460752303423488 )
where attrEx != 0

attrEx Type : BIGINT

Error:

Operand data type numeric is invalid for '~' operator.

CodePudding user response:

You need to cast it to bigint

UPDATE Table
SET attrEx= attrEx & (~CAST(576460752303423488 AS bigint) )
where attrEx != 0

This is documented here

Functions return bigint only if the parameter expression is a bigint data type. SQL Server does not automatically promote other integer data types (tinyint, smallint, and int) to bigint.
...snip...
Integer constants greater than 2,147,483,647 are converted to the decimal data type, not the bigint data type.

  • Related