<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: T-SQL Bitwise Operations</title>
	<atom:link href="http://sqlfool.com/2009/02/bitwise-operations/feed/" rel="self" type="application/rss+xml" />
	<link>http://sqlfool.com/2009/02/bitwise-operations/</link>
	<description>Adventures in SQL Tuning - a blog for the rest of us</description>
	<lastBuildDate>Thu, 04 Feb 2010 08:21:02 -0700</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.1</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: Mike</title>
		<link>http://sqlfool.com/2009/02/bitwise-operations/comment-page-1/#comment-5037</link>
		<dc:creator>Mike</dc:creator>
		<pubDate>Wed, 23 Dec 2009 18:55:42 +0000</pubDate>
		<guid isPermaLink="false">http://sqlfool.com/?p=435#comment-5037</guid>
		<description>This area of programming is becoming a lost art.  Storing and retreiving data by using bit masks (as this article describes) is still a common use of bitwise operators, but there are so many other uses, namely data manipulation and calculation, that are becoming forgotton.</description>
		<content:encoded><![CDATA[<p>This area of programming is becoming a lost art.  Storing and retreiving data by using bit masks (as this article describes) is still a common use of bitwise operators, but there are so many other uses, namely data manipulation and calculation, that are becoming forgotton.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: SQL Notes &#171; 36 Chambers &#8211; The Legendary Journeys: Execution to the max!</title>
		<link>http://sqlfool.com/2009/02/bitwise-operations/comment-page-1/#comment-4973</link>
		<dc:creator>SQL Notes &#171; 36 Chambers &#8211; The Legendary Journeys: Execution to the max!</dc:creator>
		<pubDate>Sun, 11 Oct 2009 02:03:59 +0000</pubDate>
		<guid isPermaLink="false">http://sqlfool.com/?p=435#comment-4973</guid>
		<description>[...] after all.  Unfortunately, one of our legacy tables at work still uses these, so fortunately, Michelle Ufford has a good primer on how to do it.  Don&#8217;t do it, [...]</description>
		<content:encoded><![CDATA[<p>[...] after all.  Unfortunately, one of our legacy tables at work still uses these, so fortunately, Michelle Ufford has a good primer on how to do it.  Don&#8217;t do it, [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Microsoft and DiscountASP.NET news</title>
		<link>http://sqlfool.com/2009/02/bitwise-operations/comment-page-1/#comment-4587</link>
		<dc:creator>Microsoft and DiscountASP.NET news</dc:creator>
		<pubDate>Thu, 25 Jun 2009 02:14:23 +0000</pubDate>
		<guid isPermaLink="false">http://sqlfool.com/?p=435#comment-4587</guid>
		<description>&lt;strong&gt;SQL Server Index Defrag Script...&lt;/strong&gt;

Hiya. . . Some of you may have already seen this, but just in case you haven&#039;t; Some excellent SQL Server...</description>
		<content:encoded><![CDATA[<p><strong>SQL Server Index Defrag Script&#8230;</strong></p>
<p>Hiya. . . Some of you may have already seen this, but just in case you haven&#8217;t; Some excellent SQL Server&#8230;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Index Defrag Script, v3.0 : SQL Fool</title>
		<link>http://sqlfool.com/2009/02/bitwise-operations/comment-page-1/#comment-4574</link>
		<dc:creator>Index Defrag Script, v3.0 : SQL Fool</dc:creator>
		<pubDate>Wed, 24 Jun 2009 00:37:31 +0000</pubDate>
		<guid isPermaLink="false">http://sqlfool.com/?p=435#comment-4574</guid>
		<description>[...] Take a SUM of the values for the days that you want excluded. So if you want an index to only be defragged on weekends, you would add up Monday through Friday (2+4+8+16+32) and use a value of 62 for the exclusionMask column. For a little more information on how this works, check out my blog post on Bitwise Operations. [...]</description>
		<content:encoded><![CDATA[<p>[...] Take a SUM of the values for the days that you want excluded. So if you want an index to only be defragged on weekends, you would add up Monday through Friday (2+4+8+16+32) and use a value of 62 for the exclusionMask column. For a little more information on how this works, check out my blog post on Bitwise Operations. [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Another perl Blog &#187; Blog Archive &#187; The world is amazing: Perl: convert decimal to binary using &#8230;</title>
		<link>http://sqlfool.com/2009/02/bitwise-operations/comment-page-1/#comment-3246</link>
		<dc:creator>Another perl Blog &#187; Blog Archive &#187; The world is amazing: Perl: convert decimal to binary using &#8230;</dc:creator>
		<pubDate>Tue, 05 May 2009 14:33:25 +0000</pubDate>
		<guid isPermaLink="false">http://sqlfool.com/?p=435#comment-3246</guid>
		<description>[...] Bitwise Operations [...]</description>
		<content:encoded><![CDATA[<p>[...] Bitwise Operations [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Ranga</title>
		<link>http://sqlfool.com/2009/02/bitwise-operations/comment-page-1/#comment-2655</link>
		<dc:creator>Ranga</dc:creator>
		<pubDate>Mon, 20 Apr 2009 18:46:11 +0000</pubDate>
		<guid isPermaLink="false">http://sqlfool.com/?p=435#comment-2655</guid>
		<description>Thanks a lot for the explanation....</description>
		<content:encoded><![CDATA[<p>Thanks a lot for the explanation&#8230;.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Michelle Ufford</title>
		<link>http://sqlfool.com/2009/02/bitwise-operations/comment-page-1/#comment-2506</link>
		<dc:creator>Michelle Ufford</dc:creator>
		<pubDate>Thu, 16 Apr 2009 18:42:14 +0000</pubDate>
		<guid isPermaLink="false">http://sqlfool.com/?p=435#comment-2506</guid>
		<description>Hi Ranga,

Thanks for the feedback!  I&#039;m glad you like the site.  :)

The &amp; operator actually has nothing to do with XML; in the example above, XML was just used to help format the result set.  The &amp; operator is returning the bitwise value if the bitwise product contains it.  To expand on the example above...

&lt;pre lang=&quot;tsql&quot;&gt;
CREATE TABLE #myTable
(
      myWeekDay                 varchar(10)
    , bitwiseProduct            tinyint
    , bitwiseValue              tinyint
    , bitwiseOperatorResults    tinyint
);

INSERT INTO #myTable
SELECT &#039;Sunday&#039;, 42, 1, 42 &amp; 1 Union All
SELECT &#039;Monday&#039;, 42, 2, 42 &amp; 2 Union All
SELECT &#039;Tuesday&#039;, 42, 4, 42 &amp; 4 Union All
SELECT &#039;Wednesday&#039;, 42, 8, 42 &amp; 8 Union All
SELECT &#039;Thursday&#039;, 42, 16, 42 &amp; 16 Union All
SELECT &#039;Friday&#039;, 42, 32, 42 &amp; 32 Union All
SELECT &#039;Saturday&#039;, 42, 64, 42 &amp; 64;
&lt;/pre&gt;

Now run these 2 queries to better examine what we&#039;re doing with the WHERE a.attributes &amp; b.attribute &lt;&gt; 0 syntax:

&lt;pre lang=&quot;tsql&quot;&gt;
SELECT * FROM #myTable;

SELECT *
FROM #myTable
WHERE bitwiseOperatorResults &lt;&gt; 0;
&lt;/pre&gt;

The first query shows you the results of passing each of the values into the bitwise product, with the use of the &amp; operator.  The second query shows you only those values that are contained in the bitwise product, which means they are &quot;selected.&quot; 

Does that help?  If not, let me know and I&#039;ll expand on it further.</description>
		<content:encoded><![CDATA[<p>Hi Ranga,</p>
<p>Thanks for the feedback!  I&#8217;m glad you like the site.  <img src='http://sqlfool.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>The &#038; operator actually has nothing to do with XML; in the example above, XML was just used to help format the result set.  The &#038; operator is returning the bitwise value if the bitwise product contains it.  To expand on the example above&#8230;</p>

<div class="wp_syntax"><div class="code"><pre class="tsql" style="font-family:monospace;"><span style="color: #0000FF;">CREATE</span> <span style="color: #0000FF;">TABLE</span> #myTable
<span style="color: #808080;">&#40;</span>
      myWeekDay                 <span style="color: #0000FF;">VARCHAR</span><span style="color: #808080;">&#40;</span><span style="color: #000;">10</span><span style="color: #808080;">&#41;</span>
    , bitwiseProduct            <span style="color: #0000FF;">TINYINT</span>
    , bitwiseValue              <span style="color: #0000FF;">TINYINT</span>
    , bitwiseOperatorResults    <span style="color: #0000FF;">TINYINT</span>
<span style="color: #808080;">&#41;</span>;
&nbsp;
<span style="color: #0000FF;">INSERT</span> <span style="color: #0000FF;">INTO</span> #myTable
<span style="color: #0000FF;">SELECT</span> <span style="color: #FF0000;">'Sunday'</span>, <span style="color: #000;">42</span>, <span style="color: #000;">1</span>, <span style="color: #000;">42</span> <span style="color: #808080;">&amp;</span> <span style="color: #000;">1</span> <span style="color: #0000FF;">UNION</span> All
<span style="color: #0000FF;">SELECT</span> <span style="color: #FF0000;">'Monday'</span>, <span style="color: #000;">42</span>, <span style="color: #000;">2</span>, <span style="color: #000;">42</span> <span style="color: #808080;">&amp;</span> <span style="color: #000;">2</span> <span style="color: #0000FF;">UNION</span> All
<span style="color: #0000FF;">SELECT</span> <span style="color: #FF0000;">'Tuesday'</span>, <span style="color: #000;">42</span>, <span style="color: #000;">4</span>, <span style="color: #000;">42</span> <span style="color: #808080;">&amp;</span> <span style="color: #000;">4</span> <span style="color: #0000FF;">UNION</span> All
<span style="color: #0000FF;">SELECT</span> <span style="color: #FF0000;">'Wednesday'</span>, <span style="color: #000;">42</span>, <span style="color: #000;">8</span>, <span style="color: #000;">42</span> <span style="color: #808080;">&amp;</span> <span style="color: #000;">8</span> <span style="color: #0000FF;">UNION</span> All
<span style="color: #0000FF;">SELECT</span> <span style="color: #FF0000;">'Thursday'</span>, <span style="color: #000;">42</span>, <span style="color: #000;">16</span>, <span style="color: #000;">42</span> <span style="color: #808080;">&amp;</span> <span style="color: #000;">16</span> <span style="color: #0000FF;">UNION</span> All
<span style="color: #0000FF;">SELECT</span> <span style="color: #FF0000;">'Friday'</span>, <span style="color: #000;">42</span>, <span style="color: #000;">32</span>, <span style="color: #000;">42</span> <span style="color: #808080;">&amp;</span> <span style="color: #000;">32</span> <span style="color: #0000FF;">UNION</span> All
<span style="color: #0000FF;">SELECT</span> <span style="color: #FF0000;">'Saturday'</span>, <span style="color: #000;">42</span>, <span style="color: #000;">64</span>, <span style="color: #000;">42</span> <span style="color: #808080;">&amp;</span> <span style="color: #000;">64</span>;</pre></div></div>

<p>Now run these 2 queries to better examine what we&#8217;re doing with the WHERE a.attributes &#038; b.attribute <> 0 syntax:</p>

<div class="wp_syntax"><div class="code"><pre class="tsql" style="font-family:monospace;"><span style="color: #0000FF;">SELECT</span> <span style="color: #808080;">*</span> <span style="color: #0000FF;">FROM</span> #myTable;
&nbsp;
<span style="color: #0000FF;">SELECT</span> <span style="color: #808080;">*</span>
<span style="color: #0000FF;">FROM</span> #myTable
<span style="color: #0000FF;">WHERE</span> bitwiseOperatorResults <span style="color: #808080;">&lt;&gt;</span> <span style="color: #000;">0</span>;</pre></div></div>

<p>The first query shows you the results of passing each of the values into the bitwise product, with the use of the &#038; operator.  The second query shows you only those values that are contained in the bitwise product, which means they are &#8220;selected.&#8221; </p>
<p>Does that help?  If not, let me know and I&#8217;ll expand on it further.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Ranga</title>
		<link>http://sqlfool.com/2009/02/bitwise-operations/comment-page-1/#comment-2505</link>
		<dc:creator>Ranga</dc:creator>
		<pubDate>Thu, 16 Apr 2009 18:01:42 +0000</pubDate>
		<guid isPermaLink="false">http://sqlfool.com/?p=435#comment-2505</guid>
		<description>Michelle,
Just saw this website today...its great, like your style!

I am kind of new to XML, couldn&#039;t understand the &amp; operator used in the below query: Can you please shed some light on this..

WHERE a.attributes &amp; b.attribute  0 



SELECT a.item
    , REPLACE( REPLACE( REPLACE(( 
        SELECT VALUE 
        FROM #statusLookup AS b 
        WHERE a.attributes &amp; b.attribute  0 
        ORDER BY b.VALUE FOR XML Raw)
        , &#039;&quot;/&gt;&lt;row value=&quot;&#039;, &#039;, &#039;), &#039;&#039;, &#039;&#039;) 
        AS &#039;attributes&#039;
FROM myTable a
ORDER BY a.item;</description>
		<content:encoded><![CDATA[<p>Michelle,<br />
Just saw this website today&#8230;its great, like your style!</p>
<p>I am kind of new to XML, couldn&#8217;t understand the &amp; operator used in the below query: Can you please shed some light on this..</p>
<p>WHERE a.attributes &amp; b.attribute  0 </p>
<p>SELECT a.item<br />
    , REPLACE( REPLACE( REPLACE((<br />
        SELECT VALUE<br />
        FROM #statusLookup AS b<br />
        WHERE a.attributes &amp; b.attribute  0<br />
        ORDER BY b.VALUE FOR XML Raw)<br />
        , &#8216;&#8221;/&gt;&lt;row value=&#8221;&#8216;, &#8216;, &#8216;), &#8221;, &#8221;)<br />
        AS &#8216;attributes&#8217;<br />
FROM myTable a<br />
ORDER BY a.item;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: View (and Disable) SQL Agent Jobs with TSQL : SQL Fool</title>
		<link>http://sqlfool.com/2009/02/bitwise-operations/comment-page-1/#comment-229</link>
		<dc:creator>View (and Disable) SQL Agent Jobs with TSQL : SQL Fool</dc:creator>
		<pubDate>Fri, 06 Feb 2009 15:07:56 +0000</pubDate>
		<guid isPermaLink="false">http://sqlfool.com/?p=435#comment-229</guid>
		<description>[...] Not sure what I&#8217;m doing with the @weekDay table? Then check out my post on bitwise operations in T-SQL. [...]</description>
		<content:encoded><![CDATA[<p>[...] Not sure what I&#8217;m doing with the @weekDay table? Then check out my post on bitwise operations in T-SQL. [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Michelle Ufford</title>
		<link>http://sqlfool.com/2009/02/bitwise-operations/comment-page-1/#comment-228</link>
		<dc:creator>Michelle Ufford</dc:creator>
		<pubDate>Fri, 06 Feb 2009 14:58:01 +0000</pubDate>
		<guid isPermaLink="false">http://sqlfool.com/?p=435#comment-228</guid>
		<description>Thanks, Denis, that&#039;s great!  The next task for me is to evaluate performance implications, and your article is giving me a jump start on that.  :)</description>
		<content:encoded><![CDATA[<p>Thanks, Denis, that&#8217;s great!  The next task for me is to evaluate performance implications, and your article is giving me a jump start on that.  <img src='http://sqlfool.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
	</item>
</channel>
</rss>
