~ 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 abigint
data type. SQL Server does not automatically promote other integer data types (tinyint
,smallint
, andint
) tobigint
.
...snip...
Integer constants greater than 2,147,483,647 are converted to thedecimal
data type, not thebigint
data type.