Sunday, March 11, 2012

drop last bit

Hi,

I have an sql script, which updates some values by using BIT operations..

ex:

UPDATE table1

SET myValue = myValue & ~mask | (availability - mask)...

Problem is, this returns a value, when written to binary, it's one bit too long!

ex:

0 1 1 1 1 1

(= 62)

which should be:

0 1 1 1 1 0

(=31)

How can I "drop" this last BIT?

(Keep in mind that I store these values as LONGINT's)...

Been fighting with this one all day..

Try this...

Code Snippet

select cast(substring(rtrim(convert(char(19),<columnName>)),1,len(rtrim(convert(char(19),<columnName>)))-1) as bigint)

No comments:

Post a Comment