JAZZ Master (7/2/2013)
martin.whitton (7/2/2013)
Danny Ocean (7/1/2013)
Good question. But i never feel to use "Bitwise AND" (&) in real working scenario. It will good, if anyone come with some real working example. 🙂It provides a neat way of sending multiple options as a single integer parameter.
For example, let's say you have a table called "Locations" with 2 columns, LocationID and Location, containing the following values:
LocationID Location
1 London
2 Dublin
4 Paris
8 Berlin
16 New York
etc...
Then you could select any combination of Location values as follows:
declare @Selection int;
set @Selection=10; -- (this will select Dublin and Paris, because Dublin's LocationID plus Paris's LocationID equals 10)
select
Location
from
Locations
where
LocationId & @Selection>0;
I'm confused. Doesn't 2 (Dublin) and 8 (Berlin) equal 10 not 2 (Dublin) and 4 (Paris)? What am I missing?
Sorry :blush:
You're absolutely right - I should have said Dublin and Berlin.