Friday, March 30, 2012

query question

I saw a query in which there was a expression
SELECT
case when credit_flag&1 = 1 then 1 else 0 end as credit_default_flag1,
case when credit_flag&2 = 2 then 1 else 0 end as credit_default_flag2,
case when credit_flag&4 = 4 then 1 else 0 end as credit_default_flag3
FROM ...
What happens when we do column & 1, column & 2
THanks
Sanjay& is the bit-wise AND operator in T-SQL. So credit_flag &
1 will return 1 on the first bit only when the first bit
from the right (of credit_flag) is set to 1. And
credit_flag & 4 will return 1 on the third bit (thus
decimal 4) only when the third bit from the right (of
credit_flag) is set to 1.
Linchi
quote:

>--Original Message--
>I saw a query in which there was a expression
>SELECT
>case when credit_flag&1 = 1 then 1 else 0 end as

credit_default_flag1,
quote:
ed">
>case when credit_flag&2 = 2 then 1 else 0 end as

credit_default_flag2,
quote:
ed">
>case when credit_flag&4 = 4 then 1 else 0 end as

credit_default_flag3
quote:
d">
>FROM ...
>
>What happens when we do column & 1, column & 2
>THanks
>Sanjay
>.
>
|||HI Linchi
Do you have some white paper or document which would explain more about thes
e bit-wise operations
I think you explained what the result would be but i am not clear how bit-wi
se operations work at first place
Thanks|||The bit-wise AND operator (also OR and XOR) is supported
in most, if not all, programming languages. You can pick
up any programming tutorial book and find information on
the bit-wise operations. You can also find the info in the
SQL Server Books Online.
Linchi
quote:

>--Original Message--
>HI Linchi
>Do you have some white paper or document which would

explain more about these bit-wise operations
quote:

>I think you explained what the result would be but i am

not clear how bit-wise operations work at first place
quote:

>Thanks
>.
>
sql

No comments:

Post a Comment