I've scenario where I need to convert an Integer value to its Negative range
As we know that, range of Integer(32 Bit) is - 231 to 231-1
When I try to get the negative value, for example 3434340000 should return -1286856352
But below return with numeric overflow, which is an expected error
SEL CAST (3434340000 AS INTEGER)
But do we have any workaround, so that when I provide a number crossing the range of INT (32 Bit) and will end up getting negative value.
Is there any way to control such exceptional handlings?
why do you need this?
WHEN CAST(x AS BIGINT) > 2147483647
THEN -(CAST(x AS BIGINT) - 2147483648)
ELSE CAST(x AS BIGINT)
END AS INT)
This matches your example.
But what result do you expect for 2147483648? 0?