Solved

# what's the meaning of ampersand in select case statement

Posted on 2011-09-29
855 Views
select name,
case sysstat2 & 57344
when 32768 then "datarows"

What's the meaning of the ampersand in front of '57344'

0
• 3
• 2
• 2
• +2

LVL 39

Accepted Solution

Pratima Pharande earned 126 total points
<% dim iRow
select name,
case sysstat2 & 57344
when 32768 then "datarows"

Meaning of this

sysstat2 & 57344   , one of this value either field value of sysstat2 or 57344  is equal to 32768  then "datarows"

in other words condition looks like this

if (sysstat2 = 32768) Or (57344 = 32768 ) then "datarows"
0

LVL 142

Assisted Solution

Guy Hengel [angelIII / a3] earned 125 total points
actually,
case sysstat2 & 57344

is doing a bitwise AND of the 2 values (aka the variable sysstat2 and 57344).
this value will then be compared to the value 32768 , if that matches ....

hope this helps
0

Author Comment

so, you say....

it compare (sysstat2 == 32768) OR (57344 == 32768) ??
0

LVL 39

Assisted Solution

Pratima Pharande earned 126 total points
yes
0

LVL 142

Assisted Solution

Guy Hengel [angelIII / a3] earned 125 total points
as posted above, I have to disagree ...
0

LVL 2

Assisted Solution

maneksh earned 186 total points
Hi,

I am afraid Pratima is wrong.

& is a bitwise operator. it converts the operands into binary and evaluates column by column.

http://manuals.sybase.com/onlinebooks/group-as/asg1250e/sqlug/@Generic__BookTextView/1719;pt=945

Maneksh

0

LVL 2

Assisted Solution

maneksh earned 186 total points
Here in your example 57344 is 1110000000000000
and 32768 is 1000000000000000

some examples of  Values of  sysstat2  that could satisfy the condition are
40959  and  32768

Hope this helps

Maneksh
0

LVL 2

Assisted Solution

maneksh earned 186 total points
Hi,

Looking at your query I think you are looking for the lock scheme of a table  which is maitained in sysstat2 table in bit representation.Bit corresponding to 8192 , 16384 and 32768 represents the lock schema and 57344 is the sum of these 3.

Hope I dint confuse

maneksh

0

LVL 50

Assisted Solution

Lowfatspread earned 63 total points
its a bitwise operator signifying a logical and operation is performed on the bit patterns of the two expressions

from

msdn
The bitwise & operator performs a bitwise logical AND between the two expressions, taking each corresponding bit for both expressions. The bits in the result are set to 1 if and only if both bits (for the current bit being resolved) in the input expressions have a value of 1; otherwise, the bit in the result is set to 0.

so basically when dealing with flags/indicators stored as a pattern of bits and you wish to test for some specific values
you calculate the numeric value of the combination that you are interested in and have that logically anded with the total option value...

you can then easier test the result to see if the desired set of conditions is present.
0

## Join & Write a Comment Already a member? Login.

### Suggested Solutions

Title # Comments Views Activity
c# code 19 56
Insert from Stored Procedure where some field/s > 0 7 32
report returning null 21 49
How to query date ranges with SQL 6 22
I remember the day when someone asked me to create a user for an application developement. The user should be able to create views and materialized views and, so, I used the following syntax: (CODE) This way, I guessed, I would ensure that use…
Background In several of the companies I have worked for, I noticed that corporate reporting is off loaded from the production database and done mainly on a clone database which needs to be kept up to date daily by various means, be it a logical…
This video shows how to copy an entire tablespace from one database to another database using Transportable Tablespace functionality.
Viewers will learn how to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.

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

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

#### Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!