SQL Bitand Operation

Posted on 2003-03-29
Medium Priority
Last Modified: 2008-01-16
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

Question by:tjdos
  • 3

Author Comment

ID: 8231523
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.


Accepted Solution

amitpagarwal earned 1000 total points
ID: 8243187
your code looks good.

Author Comment

ID: 8259699
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.

Author Comment

ID: 8322216
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.

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you try to migrate from Elastix to Issabel, you will face a lot of issues. These problems are inevitable but fortunately, you can fix them. In the guide below, I will explain how I performed the migration while keeping all data and successfully t…
Whether you have a site with just static html pages or a dynamic database-driven one, this step-by-step migration guide will help you get started with your new DV server. This guide is by no means comprehensive but it should cover the basics to get …
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…
How can you see what you are working on when you want to see it while you to save a copy? Add a "Save As" icon to the Quick Access Toolbar, or QAT. That way, when you save a copy of a query, form, report, or other object you are modifying, you…

612 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question