Link to home
Start Free TrialLog in
Avatar of tjdos
tjdos

asked on

SQL Bitand Operation

Hi there,

I would like to know how I can perform a
bitand operation on a Sybase database field
using an SQL statement.

I have a table and one of the fields 'flags'
requires bitand operations. If I update flags
field to be 1024 using a standard update statement
I overwrite all the other flags that have been set
(through bitand operations) for that particular record.

I would be really obliged if some one could help me out
on this one.

Thanks in advance

Avatar of tjdos
tjdos

ASKER

I think I might have discovered the answer to my own question. I think it is:

update TableA set Flags = (Flags & 1024) where id = 1

I know the & works in select statements but I never thought of using it in an update statement.

I'll have to wait till monday to check whether this works
but anyone can confirm that I am right (or inform me if I'm wrong) before then I would appreciate it.

ASKER CERTIFIED SOLUTION
Avatar of amitpagarwal
amitpagarwal
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of tjdos

ASKER

I have discovered the actual answer to this question:

update TableA set flags = flags | 1024 where id = 1

My first solution was actually incorrect as all it did was update the field to 0 or 1 depending on whether 1024 flag had been set or not through a bitand operation.
Avatar of tjdos

ASKER

Today's your lucky day!!

Hi there. Your answer didn't really help but I think I need to award these points to someone or else they'll just be hanging there with nobody able to use them.