Wednesday, March 7, 2012

How can I workaround this problem?

Hello everbody,

this query:

SELECT * FROM TBL_DEVICE_DRIVERS

WHERE (DD_CATEGORIES & 2147483648) > 0

bring the error message:

Invalid operator for data type.

The value 2147483648 is hex 0x80000000 for bitwise

joining defined.

I try to cast it to decimal, but it does not work.

Have anybody an idea?

Thanks for answers!

hi,

what is the datatype of DD_CATEGORIES column? The bitwise operator works only on int datatypes hence the Invalid Operator for DataType.

ADD'L:

I think what happens is an overflow of the datatype : 2147483648 (max int), so cast the constant (2147483648) to bigint ex:

SELECT someCol & CAST(2147483648 AS BIGINT)

HTH|||

Will you please elaborate what you want to achive? as far as i understand you are try to make logical AND operation in the where clause as "DD_CATEGORIES & 2147483648".

what type of DD_CATRGORIES is ? try to check it data type

OR send the table structure & some semple data to, so that we can check it.

Gurpreet S. Gill

|||

Thomas:

Good question! Look at this:

-- -
-- Representation problem with 0x80000000
--
-- Even though 0x80000000 is a valid integer representation of -2147483648, MS SQL Server does
-- not seem to interpret this constant as an integer.
--
-- 1. The datalength of -2147483648 is 5; this is clearly not an INTEGER representation.
-- 2. When the "constant" -2147483648 is converted to binary its representation is 0x0A00000000
-- and NOT 0x80000000.
-- 3. If -2147483648 is cast as an integer, it then takes on the 0x80000000 representation.
-- 4. When -2147483648 is cast as an integer it can now be operated on by the & operator.
--
-- Not what you expected is it!
-- -


select datalength ( -2147483648) as Results

Results
--
5


select convert (binary(5), -2147483648) as Results

Results
0x0A00000000


select convert (binary(4), cast(-2147483648 as int)) as results
results
-
0x80000000


select convert (binary (4), cast(-2147483648 as int) & cast(-2147483648 as int)) as Results

Results
-
0x80000000


Dave

No comments:

Post a Comment