December 21, 2011 at 11:12 am
I am trying to understand the practical implementation of & (Bitwise AND).
In what scenarios should we use & (Bitwise AND) operator in SQL ?
December 21, 2011 at 11:39 am
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
December 21, 2011 at 11:46 am
December 21, 2011 at 12:01 pm
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
===========
December 21, 2011 at 12:05 pm
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
December 21, 2011 at 3:30 pm
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.
December 21, 2011 at 3:39 pm
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. 😀
December 21, 2011 at 4:36 pm
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.
December 27, 2011 at 7:55 am
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