& (Bitwise AND).

  • I am trying to understand the practical implementation of & (Bitwise AND).

    In what scenarios should we use & (Bitwise AND) operator in SQL ?

  • Only where you need to do bitwise comparisons.

    I've been working with databases and their code for about 11 years, and I've never yet needed to use one.

    They're mainly used for very low-level programming, like in embedded chips with much less powerful processors than you're likely to find on a database server.

    In that sense, it might make sense to use them in embedded SQL databases. I haven't programmed those, so really can't speak to it.

    Why do you ask? Come up on a test or something?

    - Gus "GSquared", RSVP, OODA, MAP, NMVP, FAQ, SAT, SQL, DNA, RNA, UOI, IOU, AM, PM, AD, BC, BCE, USA, UN, CF, ROFL, LOL, ETC
    Property of The Thread

    "Nobody knows the age of the human race, but everyone agrees it's old enough to know better." - Anon

  • Only time I've used it has been in COLUMNS_UPDATED filters for triggers.

    └> bt



    Forum Etiquette: How to post data/code on a forum to get the best help[/url]

  • GSquared,

    I was reviewing code written by another developer and came across scenarios

    where is he has been checking AND of two columns

    Application ID and Application Mask

    ===========

    ..WHERE ApplicationMask & Application_ID = Application_ID

    ===========

  • WangcChiKaBastar (12/21/2011)


    GSquared,

    I was reviewing code written by another developer and came across scenarios

    where is he has been checking AND of two columns

    Application ID and Application Mask

    ===========

    ..WHERE ApplicationMask & Application_ID = Application_ID

    ===========

    Makes sense.

    - Gus "GSquared", RSVP, OODA, MAP, NMVP, FAQ, SAT, SQL, DNA, RNA, UOI, IOU, AM, PM, AD, BC, BCE, USA, UN, CF, ROFL, LOL, ETC
    Property of The Thread

    "Nobody knows the age of the human race, but everyone agrees it's old enough to know better." - Anon

  • I've used it several times. It has either been low-level data conversion (UTF8 to UTF16 and back, binary(8) to float) or working with bit mapped values, like @val & 0x1 = 0x1 means read only.



    Ole Kristian Velstadbråten Bangås - Virinco - Facebook - Twitter

    Concatenating Row Values in Transact-SQL[/url]

  • GSquared (12/21/2011)


    Only where you need to do bitwise comparisons.

    I've been working with databases and their code for about 11 years, and I've never yet needed to use one

    I find excuses to avoid bit comparison. It’s out of my league. 😀

  • I encountered an example where, due to space considerations, bitmask columns were used to store up to 63 values such as user preferences or actions in one column. It was a challenge to work with them, but kind of fun once I got the hang of it. They are also used in some system tables.

  • We use it for very low-level permission checking. Every object has a bit-mask with permission levels of READ/WRITE/CREATE/DELETE/ASSOCIATE established as numerical values equating to a specific bit.

    The T-SQL stored procedures always run a check to see if the user has permission to do whatever it is that they are trying to do. Probably very similar to Windows ACL settings.

Viewing 9 posts - 1 through 8 (of 8 total)

You must be logged in to reply to this topic. Login to reply