<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	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/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Scratchbox &#124; Zach Stagers</title>
	<atom:link href="http://scratchbox.co.uk/feed/" rel="self" type="application/rss+xml" />
	<link>http://scratchbox.co.uk</link>
	<description>SQL Server Developer and Administrator</description>
	<lastBuildDate>Thu, 17 May 2012 20:25:04 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
		<item>
		<title>Returning Tabular Data as XML with FOR XML AUTO</title>
		<link>http://scratchbox.co.uk/2012/05/returning-tabular-data-as-xml-with-for-xml-auto/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=returning-tabular-data-as-xml-with-for-xml-auto</link>
		<comments>http://scratchbox.co.uk/2012/05/returning-tabular-data-as-xml-with-for-xml-auto/#comments</comments>
		<pubDate>Thu, 17 May 2012 20:25:04 +0000</pubDate>
		<dc:creator>Zach Stagers</dc:creator>
				<category><![CDATA[SQL]]></category>
		<category><![CDATA[Elements]]></category>
		<category><![CDATA[FOR XML AUTO]]></category>
		<category><![CDATA[XML]]></category>
		<category><![CDATA[XSINIL]]></category>

		<guid isPermaLink="false">http://scratchbox.co.uk/?p=103</guid>
		<description><![CDATA[About a week ago I posted on FOR XML RAW, this time it’s FOR XML AUTO‘s turn. The two are actioned via very similar syntax, but operate slightly differently. Auto is probably named “Auto” because it performs a lot of &#8230; <a href="http://scratchbox.co.uk/2012/05/returning-tabular-data-as-xml-with-for-xml-auto/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>About a week ago I posted on <a href="http://scratchbox.co.uk/2012/05/returning-tabular-data-as-xml-with-for-xml-raw/">FOR XML RAW</a>, this time it’s FOR XML AUTO‘s turn.</p>
<p>The two are actioned via very similar syntax, but operate slightly differently. Auto is probably named “Auto” because it performs a lot of the XML node naming for you. There are also a couple of other differences which I’ll explain in this post.</p>
<p>With FOR XML AUTO, you don’t have the ability to name your row’s like you do in RAW. This is because their names are derived from the aliases given to the tables in your query. For example, having a table named Person, and using FOR XML AUTO against this table would give your rows a name of “Person”. This is the same as using FOR XML RAW(&#8216;Person&#8217;), see below for a literal example of this:</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> Person
<span style="color: #0000FF;">FOR</span> XML AUTO</pre></div></div>


<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> Person
<span style="color: #0000FF;">FOR</span> XML RAW<span style="color: #808080;">&#40;</span><span style="color: #FF0000;">'Person'</span><span style="color: #808080;">&#41;</span></pre></div></div>

<p>Both of the above examples would return the below XML:</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Person</span> <span style="color: #000066;">PersonId</span>=<span style="color: #ff0000;">&quot;1&quot;</span> <span style="color: #000066;">Name</span>=<span style="color: #ff0000;">&quot;Zach Stagers&quot;</span> <span style="color: #000066;">Age</span>=<span style="color: #ff0000;">&quot;22&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span></pre></div></div>

<p>As with RAW, you can specify your root element in AUTO:</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> Person
<span style="color: #0000FF;">FOR</span> XML AUTO, ROOT<span style="color: #808080;">&#40;</span><span style="color: #FF0000;">'People'</span><span style="color: #808080;">&#41;</span></pre></div></div>

<p>The above would return the exact same XML data, but with the specified root element wrapped around it.</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;People<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
 <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Person</span> <span style="color: #000066;">PersonId</span>=<span style="color: #ff0000;">&quot;1&quot;</span> <span style="color: #000066;">Name</span>=<span style="color: #ff0000;">&quot;Zach Stagers&quot;</span> <span style="color: #000066;">Age</span>=<span style="color: #ff0000;">&quot;22&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/People<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p>The attributes of the person row can further be split out into their own elements by specifying ELEMENTS, and can also be given a namespace and the ability to handle SQL NULL‘s by specifying XSINIL</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> Person
<span style="color: #0000FF;">FOR</span> XML AUTO, ROOT<span style="color: #808080;">&#40;</span><span style="color: #FF0000;">'People'</span><span style="color: #808080;">&#41;</span>, ELEMENTS, XS<span style="color: #808080;">IN</span>IL</pre></div></div>

<p>The above example would return:</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;People</span> <span style="color: #000066;">xmlns:xsi</span>=<span style="color: #ff0000;">&quot;http://www.w3.org/2001/XMLSchema-instance&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
 <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Person<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;PersonId<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>1<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/PersonId<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>Zach Stagers<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/Name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Age<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>22<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/Age<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
 <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/Person<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/People<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p>There are a couple of other things to remember when using FOR XML AUTO, and that is that the order of your XML elements is down the order in which your columns are specified. For example, executing the below two queries would give you the same information, but using them with FOR XML AUTO will give you completely different XML:</p>

<div class="wp_syntax"><div class="code"><pre class="tsql" style="font-family:monospace;"><span style="color: #0000FF;">SELECT</span> Person.<span style="color: #202020;">Name</span>,
       Orders.<span style="color: #202020;">Item</span>
&nbsp;
<span style="color: #0000FF;">FROM</span> Person 
     <span style="color: #808080;">JOIN</span> Orders <span style="color: #0000FF;">ON</span> Orders.<span style="color: #202020;">PersonId</span> <span style="color: #808080;">=</span> Person.<span style="color: #202020;">PersonId</span>
&nbsp;
<span style="color: #0000FF;">FOR</span> XML AUTO, ROOT<span style="color: #808080;">&#40;</span><span style="color: #FF0000;">'PeopleWithOrders'</span><span style="color: #808080;">&#41;</span></pre></div></div>

<p>Returns:</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;PeopleWithOrders<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
 <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Person</span> <span style="color: #000066;">Name</span>=<span style="color: #ff0000;">&quot;Zach Stagers&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Orders</span> <span style="color: #000066;">Item</span>=<span style="color: #ff0000;">&quot;Bike&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Orders</span> <span style="color: #000066;">Item</span>=<span style="color: #ff0000;">&quot;Laptop&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Orders</span> <span style="color: #000066;">Item</span>=<span style="color: #ff0000;">&quot;Phone&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
 <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/Person<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/PeopleWithOrders<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>


<div class="wp_syntax"><div class="code"><pre class="tsql" style="font-family:monospace;"><span style="color: #0000FF;">SELECT</span> Orders.<span style="color: #202020;">Item</span>,
       Person.<span style="color: #202020;">Name</span>
&nbsp;
<span style="color: #0000FF;">FROM</span> Person 
     <span style="color: #808080;">JOIN</span> Orders <span style="color: #0000FF;">ON</span> Orders.<span style="color: #202020;">PersonId</span> <span style="color: #808080;">=</span> Person.<span style="color: #202020;">PersonId</span>
&nbsp;
<span style="color: #0000FF;">FOR</span> XML AUTO, ROOT<span style="color: #808080;">&#40;</span><span style="color: #FF0000;">'PeopleWithOrders'</span><span style="color: #808080;">&#41;</span></pre></div></div>

<p>The above query, with the columns swapped over will return:</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;PeopleWithOrders<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
 <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Orders</span> <span style="color: #000066;">Item</span>=<span style="color: #ff0000;">&quot;Bike&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Person</span> <span style="color: #000066;">Name</span>=<span style="color: #ff0000;">&quot;Zach Stagers&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
 <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/Orders<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
 <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Orders</span> <span style="color: #000066;">Item</span>=<span style="color: #ff0000;">&quot;Laptop&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Person</span> <span style="color: #000066;">Name</span>=<span style="color: #ff0000;">&quot;Zach Stagers&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
 <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/Orders<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
 <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Orders</span> <span style="color: #000066;">Item</span>=<span style="color: #ff0000;">&quot;Phone&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Person</span> <span style="color: #000066;">Name</span>=<span style="color: #ff0000;">&quot;Zach Stagers&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
 <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/Orders<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/PeopleWithOrders<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p>So, you just need to remember that the order of the columns is what specifies the output of your XML, not the order of the tables in the FROM clause. The names given to the tables, however, specifies the names given to the XML nodes.</p>
<div class="lightsocial_container"><a class="lightsocial_a" href="http://digg.com/submit?url=http%3A%2F%2Fscratchbox.co.uk%2F2012%2F05%2Freturning-tabular-data-as-xml-with-for-xml-auto%2F&amp;title=Returning+Tabular+Data+as+XML+with+FOR+XML+AUTO" target="_blank"><img class="lightsocial_img" src="http://scratchbox.co.uk/wp-content/plugins/light-social/digg.png" alt="Digg This" title="Digg This" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.reddit.com/submit?url=http%3A%2F%2Fscratchbox.co.uk%2F2012%2F05%2Freturning-tabular-data-as-xml-with-for-xml-auto%2F&amp;title=Returning+Tabular+Data+as+XML+with+FOR+XML+AUTO" target="_blank"><img class="lightsocial_img" src="http://scratchbox.co.uk/wp-content/plugins/light-social/reddit.png" alt="Reddit This" title="Reddit This" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.stumbleupon.com/submit?url=http%3A%2F%2Fscratchbox.co.uk%2F2012%2F05%2Freturning-tabular-data-as-xml-with-for-xml-auto%2F&amp;title=Returning+Tabular+Data+as+XML+with+FOR+XML+AUTO" target="_blank"><img class="lightsocial_img" src="http://scratchbox.co.uk/wp-content/plugins/light-social/stumbleupon.png" alt="Stumble Now!" title="Stumble Now!" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://buzz.yahoo.com/buzz?targetUrl=http%3A%2F%2Fscratchbox.co.uk%2F2012%2F05%2Freturning-tabular-data-as-xml-with-for-xml-auto%2F&amp;headline=Returning+Tabular+Data+as+XML+with+FOR+XML+AUTO" target="_blank"><img class="lightsocial_img" src="http://scratchbox.co.uk/wp-content/plugins/light-social/yahoo_buzz.png" alt="Buzz This" title="Buzz This" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.dzone.com/links/add.html?title=Returning+Tabular+Data+as+XML+with+FOR+XML+AUTO&amp;url=http%3A%2F%2Fscratchbox.co.uk%2F2012%2F05%2Freturning-tabular-data-as-xml-with-for-xml-auto%2F" target="_blank"><img class="lightsocial_img" src="http://scratchbox.co.uk/wp-content/plugins/light-social/dzone.png" alt="Vote on DZone" title="Vote on DZone" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.facebook.com/sharer.php?t=Returning+Tabular+Data+as+XML+with+FOR+XML+AUTO&amp;u=http%3A%2F%2Fscratchbox.co.uk%2F2012%2F05%2Freturning-tabular-data-as-xml-with-for-xml-auto%2F" target="_blank"><img class="lightsocial_img" src="http://scratchbox.co.uk/wp-content/plugins/light-social/facebook.png" alt="Share on Facebook" title="Share on Facebook" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://delicious.com/save?title=Returning+Tabular+Data+as+XML+with+FOR+XML+AUTO&amp;url=http%3A%2F%2Fscratchbox.co.uk%2F2012%2F05%2Freturning-tabular-data-as-xml-with-for-xml-auto%2F" target="_blank"><img class="lightsocial_img" src="http://scratchbox.co.uk/wp-content/plugins/light-social/delicious.png" alt="Bookmark this on Delicious" title="Bookmark this on Delicious" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.dotnetkicks.com/kick/?title=Returning+Tabular+Data+as+XML+with+FOR+XML+AUTO&amp;url=http%3A%2F%2Fscratchbox.co.uk%2F2012%2F05%2Freturning-tabular-data-as-xml-with-for-xml-auto%2F" target="_blank"><img class="lightsocial_img" src="http://scratchbox.co.uk/wp-content/plugins/light-social/dotnetkicks.png" alt="Kick It on DotNetKicks.com" title="Kick It on DotNetKicks.com" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://dotnetshoutout.com/Submit?title=Returning+Tabular+Data+as+XML+with+FOR+XML+AUTO&amp;url=http%3A%2F%2Fscratchbox.co.uk%2F2012%2F05%2Freturning-tabular-data-as-xml-with-for-xml-auto%2F" target="_blank"><img class="lightsocial_img" src="http://scratchbox.co.uk/wp-content/plugins/light-social/dotnetshoutout.png" alt="Shout it" title="Shout it" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.linkedin.com/shareArticle?mini=true&amp;url=http%3A%2F%2Fscratchbox.co.uk%2F2012%2F05%2Freturning-tabular-data-as-xml-with-for-xml-auto%2F&amp;title=Returning+Tabular+Data+as+XML+with+FOR+XML+AUTO&amp;summary=&amp;source=" target="_blank"><img class="lightsocial_img" src="http://scratchbox.co.uk/wp-content/plugins/light-social/linkedin.png" alt="Share on LinkedIn" title="Share on LinkedIn" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.technorati.com/faves?add=http%3A%2F%2Fscratchbox.co.uk%2F2012%2F05%2Freturning-tabular-data-as-xml-with-for-xml-auto%2F" target="_blank"><img class="lightsocial_img" src="http://scratchbox.co.uk/wp-content/plugins/light-social/technorati.png" alt="Bookmark this on Technorati" title="Bookmark this on Technorati" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://twitter.com/home?status=Reading+http%3A%2F%2Fscratchbox.co.uk%2F2012%2F05%2Freturning-tabular-data-as-xml-with-for-xml-auto%2F" target="_blank"><img class="lightsocial_img" src="http://scratchbox.co.uk/wp-content/plugins/light-social/twitter.png" alt="Post on Twitter" title="Post on Twitter" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.google.com/buzz/post?url=http%3A%2F%2Fscratchbox.co.uk%2F2012%2F05%2Freturning-tabular-data-as-xml-with-for-xml-auto%2F" target="_blank"><img class="lightsocial_img" src="http://scratchbox.co.uk/wp-content/plugins/light-social/google_buzz.png" alt="Google Buzz (aka. Google Reader)" title="Google Buzz (aka. Google Reader)" /></a>&nbsp;&nbsp;</div>]]></content:encoded>
			<wfw:commentRss>http://scratchbox.co.uk/2012/05/returning-tabular-data-as-xml-with-for-xml-auto/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Recursive CTEs</title>
		<link>http://scratchbox.co.uk/2012/05/recursive-ctes/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=recursive-ctes</link>
		<comments>http://scratchbox.co.uk/2012/05/recursive-ctes/#comments</comments>
		<pubDate>Wed, 16 May 2012 15:34:59 +0000</pubDate>
		<dc:creator>Zach Stagers</dc:creator>
				<category><![CDATA[SQL]]></category>
		<category><![CDATA[CTE]]></category>
		<category><![CDATA[Recursive]]></category>

		<guid isPermaLink="false">http://scratchbox.co.uk/?p=161</guid>
		<description><![CDATA[Recursive Common Table Expressions allow you to perform a recursive query, without the use of a resource intensive Cursor. In this post, I’ll show you how to write a very simple Recursive CTE, and explain how it works. The example &#8230; <a href="http://scratchbox.co.uk/2012/05/recursive-ctes/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Recursive Common Table Expressions allow you to perform a recursive query, without the use of a resource intensive Cursor.</p>
<p>In this post, I’ll show you how to write a very simple Recursive CTE, and explain how it works.</p>
<p>The example that I’ll be working with in this post is as below:</p>

<div class="wp_syntax"><div class="code"><pre class="tsql" style="font-family:monospace;">;WITH RCTE <span style="color: #0000FF;">AS</span>
       <span style="color: #808080;">&#40;</span>
        <span style="color: #0000FF;">SELECT</span> <span style="color: #000;">1</span> <span style="color: #0000FF;">AS</span> <span style="color: #808080;">&#91;</span>Recursion <span style="color: #0000FF;">Level</span><span style="color: #808080;">&#93;</span>, <span style="color: #FF0000;">'A'</span> <span style="color: #808080;">&#91;</span>Type<span style="color: #808080;">&#93;</span>
&nbsp;
        <span style="color: #0000FF;">UNION</span> <span style="color: #808080;">ALL</span>
&nbsp;
        <span style="color: #0000FF;">SELECT</span> <span style="color: #808080;">&#91;</span>Recursion <span style="color: #0000FF;">Level</span><span style="color: #808080;">&#93;</span> <span style="color: #808080;">+</span><span style="color: #000;">1</span> <span style="color: #0000FF;">AS</span> <span style="color: #808080;">&#91;</span>Recursion <span style="color: #0000FF;">Level</span><span style="color: #808080;">&#93;</span>, <span style="color: #FF0000;">'R'</span> <span style="color: #808080;">&#91;</span>Type<span style="color: #808080;">&#93;</span>
        <span style="color: #0000FF;">FROM</span> RCTE
        <span style="color: #0000FF;">WHERE</span> <span style="color: #808080;">&#91;</span>Recursion <span style="color: #0000FF;">Level</span><span style="color: #808080;">&#93;</span> <span style="color: #808080;">&lt;</span> <span style="color: #000;">5</span>
       <span style="color: #808080;">&#41;</span>
&nbsp;
<span style="color: #0000FF;">SELECT</span> <span style="color: #808080;">*</span> <span style="color: #0000FF;">FROM</span> RCTE
<span style="color: #0000FF;">OPTION</span><span style="color: #808080;">&#40;</span>MAXRECURSION <span style="color: #000;">4</span><span style="color: #808080;">&#41;</span></pre></div></div>

<p>This example obviously has no practical use, but it&#8217;s good for showing how a Recursive CTE works.</p>
<p>The query starts in the exact same way as a normal CTE, ;WITH RCTE AS. The semicolon terminates any SQL defined before the CTE, and it&#8217;s best practice to add a semicolon here for that reason. If any preceding code (Commonly the declaration of variables) isn&#8217;t terminated by a semicolon, an error will occur.</p>
<p>The second line, SELECT 1 AS [Recursion Level], &#8216;A&#8217; [Type] is known as the &#8220;Anchor Member&#8221;. This query defines the base level item that you would like to build upon. This simple select just creates a single record with two columns.</p>
<p>UNION ALL joins the two parts of the recursive query together, and must be defined after your anchor query.</p>
<p>The query defined after the UNION ALL is known as the &#8220;Recursive Member&#8221;. This query must reference the CTE in its FROM clause. This is so the query knows what base values it has, and can therefore build upon. The where clause, WHERE [Recursion Level] < 5, is a terminator statement, which stops the query from looping indefinitely. The CTE is then closed off with a closing a bracket.</p>
<p>A simple SELECT * FROM RCTE is all that is needed to pull back all of the required information from the CTE in this example.</p>
<p>OPTION(MAXRECURSION 4) is essentially another safety net to stop the query from spiralling into an infinite loop. This stops the query from running at a maximum of 4 recursions, but be aware that if 4 recursions isn't enough to extract all of the data within the loop - an error will occur. For example, If I changed my WHERE clause to less than 6 in the Recursive Member, and left my Max Recursion option at 4 I would recieve the following error:</p>
<p>The statement terminated. The maximum recursion 4 has been exhausted before statement completion.</p>
<p>The Max Recursion clause is optional.</p>
<p>The result set from the example query would like the below:</p>
<div id="attachment_162" class="wp-caption alignnone" style="width: 217px"><img src="http://scratchbox.co.uk/wp-content/uploads/2012/05/RCTE-Result.jpg" alt="Recursive CTE Result" title="Recursive CTE Result" width="207" height="188" class="size-full wp-image-162" /><p class="wp-caption-text">Recursive CTE Result</p></div>
<p>As you can see, 5 results were returned &#8211; even though WHERE [Recursion Level] < 5 was specified in the Recursive Member, and OPTION(MAXRECURSION 4) is defined in the outer query. This is because the Anchor Member (First record in the result set, type &#8220;A&#8221;) doesn&#8217;t count as a recursion. There are, however, 4 recursion records (type &#8220;R&#8221;).</p>
<p>A more practical use of a Recursive CTE would be to build something like a family tree, or a companies employee structure.</p>
<div class="lightsocial_container"><a class="lightsocial_a" href="http://digg.com/submit?url=http%3A%2F%2Fscratchbox.co.uk%2F2012%2F05%2Frecursive-ctes%2F&amp;title=Recursive+CTEs" target="_blank"><img class="lightsocial_img" src="http://scratchbox.co.uk/wp-content/plugins/light-social/digg.png" alt="Digg This" title="Digg This" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.reddit.com/submit?url=http%3A%2F%2Fscratchbox.co.uk%2F2012%2F05%2Frecursive-ctes%2F&amp;title=Recursive+CTEs" target="_blank"><img class="lightsocial_img" src="http://scratchbox.co.uk/wp-content/plugins/light-social/reddit.png" alt="Reddit This" title="Reddit This" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.stumbleupon.com/submit?url=http%3A%2F%2Fscratchbox.co.uk%2F2012%2F05%2Frecursive-ctes%2F&amp;title=Recursive+CTEs" target="_blank"><img class="lightsocial_img" src="http://scratchbox.co.uk/wp-content/plugins/light-social/stumbleupon.png" alt="Stumble Now!" title="Stumble Now!" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://buzz.yahoo.com/buzz?targetUrl=http%3A%2F%2Fscratchbox.co.uk%2F2012%2F05%2Frecursive-ctes%2F&amp;headline=Recursive+CTEs" target="_blank"><img class="lightsocial_img" src="http://scratchbox.co.uk/wp-content/plugins/light-social/yahoo_buzz.png" alt="Buzz This" title="Buzz This" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.dzone.com/links/add.html?title=Recursive+CTEs&amp;url=http%3A%2F%2Fscratchbox.co.uk%2F2012%2F05%2Frecursive-ctes%2F" target="_blank"><img class="lightsocial_img" src="http://scratchbox.co.uk/wp-content/plugins/light-social/dzone.png" alt="Vote on DZone" title="Vote on DZone" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.facebook.com/sharer.php?t=Recursive+CTEs&amp;u=http%3A%2F%2Fscratchbox.co.uk%2F2012%2F05%2Frecursive-ctes%2F" target="_blank"><img class="lightsocial_img" src="http://scratchbox.co.uk/wp-content/plugins/light-social/facebook.png" alt="Share on Facebook" title="Share on Facebook" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://delicious.com/save?title=Recursive+CTEs&amp;url=http%3A%2F%2Fscratchbox.co.uk%2F2012%2F05%2Frecursive-ctes%2F" target="_blank"><img class="lightsocial_img" src="http://scratchbox.co.uk/wp-content/plugins/light-social/delicious.png" alt="Bookmark this on Delicious" title="Bookmark this on Delicious" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.dotnetkicks.com/kick/?title=Recursive+CTEs&amp;url=http%3A%2F%2Fscratchbox.co.uk%2F2012%2F05%2Frecursive-ctes%2F" target="_blank"><img class="lightsocial_img" src="http://scratchbox.co.uk/wp-content/plugins/light-social/dotnetkicks.png" alt="Kick It on DotNetKicks.com" title="Kick It on DotNetKicks.com" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://dotnetshoutout.com/Submit?title=Recursive+CTEs&amp;url=http%3A%2F%2Fscratchbox.co.uk%2F2012%2F05%2Frecursive-ctes%2F" target="_blank"><img class="lightsocial_img" src="http://scratchbox.co.uk/wp-content/plugins/light-social/dotnetshoutout.png" alt="Shout it" title="Shout it" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.linkedin.com/shareArticle?mini=true&amp;url=http%3A%2F%2Fscratchbox.co.uk%2F2012%2F05%2Frecursive-ctes%2F&amp;title=Recursive+CTEs&amp;summary=&amp;source=" target="_blank"><img class="lightsocial_img" src="http://scratchbox.co.uk/wp-content/plugins/light-social/linkedin.png" alt="Share on LinkedIn" title="Share on LinkedIn" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.technorati.com/faves?add=http%3A%2F%2Fscratchbox.co.uk%2F2012%2F05%2Frecursive-ctes%2F" target="_blank"><img class="lightsocial_img" src="http://scratchbox.co.uk/wp-content/plugins/light-social/technorati.png" alt="Bookmark this on Technorati" title="Bookmark this on Technorati" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://twitter.com/home?status=Reading+http%3A%2F%2Fscratchbox.co.uk%2F2012%2F05%2Frecursive-ctes%2F" target="_blank"><img class="lightsocial_img" src="http://scratchbox.co.uk/wp-content/plugins/light-social/twitter.png" alt="Post on Twitter" title="Post on Twitter" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.google.com/buzz/post?url=http%3A%2F%2Fscratchbox.co.uk%2F2012%2F05%2Frecursive-ctes%2F" target="_blank"><img class="lightsocial_img" src="http://scratchbox.co.uk/wp-content/plugins/light-social/google_buzz.png" alt="Google Buzz (aka. Google Reader)" title="Google Buzz (aka. Google Reader)" /></a>&nbsp;&nbsp;</div>]]></content:encoded>
			<wfw:commentRss>http://scratchbox.co.uk/2012/05/recursive-ctes/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Connecting SSMS through a specified port</title>
		<link>http://scratchbox.co.uk/2012/05/connecting-ssms-through-a-specified-port/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=connecting-ssms-through-a-specified-port</link>
		<comments>http://scratchbox.co.uk/2012/05/connecting-ssms-through-a-specified-port/#comments</comments>
		<pubDate>Tue, 15 May 2012 22:32:58 +0000</pubDate>
		<dc:creator>Zach Stagers</dc:creator>
				<category><![CDATA[SQL Server Management Studio]]></category>
		<category><![CDATA[Port Specification]]></category>

		<guid isPermaLink="false">http://scratchbox.co.uk/?p=157</guid>
		<description><![CDATA[I recently needed to connect my SQL Server Management Studio to a database that wasn’t using the default port of 1433. I’d never needed to do this before, and assumed I’d just need to add :port-number after the IP of &#8230; <a href="http://scratchbox.co.uk/2012/05/connecting-ssms-through-a-specified-port/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>I recently needed to connect my SQL Server Management Studio to a database that wasn’t using the default port of 1433. I’d never needed to do this before, and assumed I’d just need to add :port-number after the IP of the server I was connecting too, but I was wrong!</p>
<p>Now, after a fair amount of googling, there appears to be plenty of information on how to set up an instance of SQL server to listen for traffic on another port – but barely anything about how to actually connect SSMS to it! So I decided to write something quick and simple about how to do it!</p>
<p>It’s still just as simple as the IP:Port, but instead of using a colon like most things, it’s a comma.</p>
<div id="attachment_158" class="wp-caption alignnone" style="width: 426px"><img src="http://scratchbox.co.uk/wp-content/uploads/2012/05/1_SQL_Login_Port.png" alt="SQL Login Port Specification" title="SQL Login Port Specification" width="416" height="308" class="size-full wp-image-158" /><p class="wp-caption-text">SQL Login Port Specification</p></div>
<div class="lightsocial_container"><a class="lightsocial_a" href="http://digg.com/submit?url=http%3A%2F%2Fscratchbox.co.uk%2F2012%2F05%2Fconnecting-ssms-through-a-specified-port%2F&amp;title=Connecting+SSMS+through+a+specified+port" target="_blank"><img class="lightsocial_img" src="http://scratchbox.co.uk/wp-content/plugins/light-social/digg.png" alt="Digg This" title="Digg This" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.reddit.com/submit?url=http%3A%2F%2Fscratchbox.co.uk%2F2012%2F05%2Fconnecting-ssms-through-a-specified-port%2F&amp;title=Connecting+SSMS+through+a+specified+port" target="_blank"><img class="lightsocial_img" src="http://scratchbox.co.uk/wp-content/plugins/light-social/reddit.png" alt="Reddit This" title="Reddit This" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.stumbleupon.com/submit?url=http%3A%2F%2Fscratchbox.co.uk%2F2012%2F05%2Fconnecting-ssms-through-a-specified-port%2F&amp;title=Connecting+SSMS+through+a+specified+port" target="_blank"><img class="lightsocial_img" src="http://scratchbox.co.uk/wp-content/plugins/light-social/stumbleupon.png" alt="Stumble Now!" title="Stumble Now!" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://buzz.yahoo.com/buzz?targetUrl=http%3A%2F%2Fscratchbox.co.uk%2F2012%2F05%2Fconnecting-ssms-through-a-specified-port%2F&amp;headline=Connecting+SSMS+through+a+specified+port" target="_blank"><img class="lightsocial_img" src="http://scratchbox.co.uk/wp-content/plugins/light-social/yahoo_buzz.png" alt="Buzz This" title="Buzz This" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.dzone.com/links/add.html?title=Connecting+SSMS+through+a+specified+port&amp;url=http%3A%2F%2Fscratchbox.co.uk%2F2012%2F05%2Fconnecting-ssms-through-a-specified-port%2F" target="_blank"><img class="lightsocial_img" src="http://scratchbox.co.uk/wp-content/plugins/light-social/dzone.png" alt="Vote on DZone" title="Vote on DZone" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.facebook.com/sharer.php?t=Connecting+SSMS+through+a+specified+port&amp;u=http%3A%2F%2Fscratchbox.co.uk%2F2012%2F05%2Fconnecting-ssms-through-a-specified-port%2F" target="_blank"><img class="lightsocial_img" src="http://scratchbox.co.uk/wp-content/plugins/light-social/facebook.png" alt="Share on Facebook" title="Share on Facebook" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://delicious.com/save?title=Connecting+SSMS+through+a+specified+port&amp;url=http%3A%2F%2Fscratchbox.co.uk%2F2012%2F05%2Fconnecting-ssms-through-a-specified-port%2F" target="_blank"><img class="lightsocial_img" src="http://scratchbox.co.uk/wp-content/plugins/light-social/delicious.png" alt="Bookmark this on Delicious" title="Bookmark this on Delicious" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.dotnetkicks.com/kick/?title=Connecting+SSMS+through+a+specified+port&amp;url=http%3A%2F%2Fscratchbox.co.uk%2F2012%2F05%2Fconnecting-ssms-through-a-specified-port%2F" target="_blank"><img class="lightsocial_img" src="http://scratchbox.co.uk/wp-content/plugins/light-social/dotnetkicks.png" alt="Kick It on DotNetKicks.com" title="Kick It on DotNetKicks.com" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://dotnetshoutout.com/Submit?title=Connecting+SSMS+through+a+specified+port&amp;url=http%3A%2F%2Fscratchbox.co.uk%2F2012%2F05%2Fconnecting-ssms-through-a-specified-port%2F" target="_blank"><img class="lightsocial_img" src="http://scratchbox.co.uk/wp-content/plugins/light-social/dotnetshoutout.png" alt="Shout it" title="Shout it" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.linkedin.com/shareArticle?mini=true&amp;url=http%3A%2F%2Fscratchbox.co.uk%2F2012%2F05%2Fconnecting-ssms-through-a-specified-port%2F&amp;title=Connecting+SSMS+through+a+specified+port&amp;summary=&amp;source=" target="_blank"><img class="lightsocial_img" src="http://scratchbox.co.uk/wp-content/plugins/light-social/linkedin.png" alt="Share on LinkedIn" title="Share on LinkedIn" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.technorati.com/faves?add=http%3A%2F%2Fscratchbox.co.uk%2F2012%2F05%2Fconnecting-ssms-through-a-specified-port%2F" target="_blank"><img class="lightsocial_img" src="http://scratchbox.co.uk/wp-content/plugins/light-social/technorati.png" alt="Bookmark this on Technorati" title="Bookmark this on Technorati" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://twitter.com/home?status=Reading+http%3A%2F%2Fscratchbox.co.uk%2F2012%2F05%2Fconnecting-ssms-through-a-specified-port%2F" target="_blank"><img class="lightsocial_img" src="http://scratchbox.co.uk/wp-content/plugins/light-social/twitter.png" alt="Post on Twitter" title="Post on Twitter" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.google.com/buzz/post?url=http%3A%2F%2Fscratchbox.co.uk%2F2012%2F05%2Fconnecting-ssms-through-a-specified-port%2F" target="_blank"><img class="lightsocial_img" src="http://scratchbox.co.uk/wp-content/plugins/light-social/google_buzz.png" alt="Google Buzz (aka. Google Reader)" title="Google Buzz (aka. Google Reader)" /></a>&nbsp;&nbsp;</div>]]></content:encoded>
			<wfw:commentRss>http://scratchbox.co.uk/2012/05/connecting-ssms-through-a-specified-port/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Changing the colour scheme in Excel 2010</title>
		<link>http://scratchbox.co.uk/2012/05/changing-the-colour-scheme-in-excel-2010/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=changing-the-colour-scheme-in-excel-2010</link>
		<comments>http://scratchbox.co.uk/2012/05/changing-the-colour-scheme-in-excel-2010/#comments</comments>
		<pubDate>Tue, 15 May 2012 11:31:24 +0000</pubDate>
		<dc:creator>Zach Stagers</dc:creator>
				<category><![CDATA[Microsoft Excel]]></category>
		<category><![CDATA[Colour Scheme]]></category>
		<category><![CDATA[Excel]]></category>

		<guid isPermaLink="false">http://scratchbox.co.uk/?p=153</guid>
		<description><![CDATA[Not a technical post from me today, but not a lot of people seem to know that Microsoft Office has several colour schemes available – Blue, Silver, and my personal favorite, Black. To choose the colour option that you’d like, &#8230; <a href="http://scratchbox.co.uk/2012/05/changing-the-colour-scheme-in-excel-2010/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Not a technical post from me today, but not a lot of people seem to know that Microsoft Office has several colour schemes available – Blue, Silver, and my personal favorite, Black.</p>
<p>To choose the colour option that you’d like, open Microsoft Excel > Click File > Options (Near the bottom in the menu on the left hand side) > On the General tab you can select your colour scheme:</p>
<div id="attachment_154" class="wp-caption alignnone" style="width: 567px"><img src="http://scratchbox.co.uk/wp-content/uploads/2012/05/ExcelColourTheme.jpg" alt="Excel Colour Theme" title="Excel Colour Theme" width="557" height="284" class="size-full wp-image-154" /><p class="wp-caption-text">Excel Colour Theme</p></div>
<div class="lightsocial_container"><a class="lightsocial_a" href="http://digg.com/submit?url=http%3A%2F%2Fscratchbox.co.uk%2F2012%2F05%2Fchanging-the-colour-scheme-in-excel-2010%2F&amp;title=Changing+the+colour+scheme+in+Excel+2010" target="_blank"><img class="lightsocial_img" src="http://scratchbox.co.uk/wp-content/plugins/light-social/digg.png" alt="Digg This" title="Digg This" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.reddit.com/submit?url=http%3A%2F%2Fscratchbox.co.uk%2F2012%2F05%2Fchanging-the-colour-scheme-in-excel-2010%2F&amp;title=Changing+the+colour+scheme+in+Excel+2010" target="_blank"><img class="lightsocial_img" src="http://scratchbox.co.uk/wp-content/plugins/light-social/reddit.png" alt="Reddit This" title="Reddit This" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.stumbleupon.com/submit?url=http%3A%2F%2Fscratchbox.co.uk%2F2012%2F05%2Fchanging-the-colour-scheme-in-excel-2010%2F&amp;title=Changing+the+colour+scheme+in+Excel+2010" target="_blank"><img class="lightsocial_img" src="http://scratchbox.co.uk/wp-content/plugins/light-social/stumbleupon.png" alt="Stumble Now!" title="Stumble Now!" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://buzz.yahoo.com/buzz?targetUrl=http%3A%2F%2Fscratchbox.co.uk%2F2012%2F05%2Fchanging-the-colour-scheme-in-excel-2010%2F&amp;headline=Changing+the+colour+scheme+in+Excel+2010" target="_blank"><img class="lightsocial_img" src="http://scratchbox.co.uk/wp-content/plugins/light-social/yahoo_buzz.png" alt="Buzz This" title="Buzz This" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.dzone.com/links/add.html?title=Changing+the+colour+scheme+in+Excel+2010&amp;url=http%3A%2F%2Fscratchbox.co.uk%2F2012%2F05%2Fchanging-the-colour-scheme-in-excel-2010%2F" target="_blank"><img class="lightsocial_img" src="http://scratchbox.co.uk/wp-content/plugins/light-social/dzone.png" alt="Vote on DZone" title="Vote on DZone" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.facebook.com/sharer.php?t=Changing+the+colour+scheme+in+Excel+2010&amp;u=http%3A%2F%2Fscratchbox.co.uk%2F2012%2F05%2Fchanging-the-colour-scheme-in-excel-2010%2F" target="_blank"><img class="lightsocial_img" src="http://scratchbox.co.uk/wp-content/plugins/light-social/facebook.png" alt="Share on Facebook" title="Share on Facebook" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://delicious.com/save?title=Changing+the+colour+scheme+in+Excel+2010&amp;url=http%3A%2F%2Fscratchbox.co.uk%2F2012%2F05%2Fchanging-the-colour-scheme-in-excel-2010%2F" target="_blank"><img class="lightsocial_img" src="http://scratchbox.co.uk/wp-content/plugins/light-social/delicious.png" alt="Bookmark this on Delicious" title="Bookmark this on Delicious" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.dotnetkicks.com/kick/?title=Changing+the+colour+scheme+in+Excel+2010&amp;url=http%3A%2F%2Fscratchbox.co.uk%2F2012%2F05%2Fchanging-the-colour-scheme-in-excel-2010%2F" target="_blank"><img class="lightsocial_img" src="http://scratchbox.co.uk/wp-content/plugins/light-social/dotnetkicks.png" alt="Kick It on DotNetKicks.com" title="Kick It on DotNetKicks.com" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://dotnetshoutout.com/Submit?title=Changing+the+colour+scheme+in+Excel+2010&amp;url=http%3A%2F%2Fscratchbox.co.uk%2F2012%2F05%2Fchanging-the-colour-scheme-in-excel-2010%2F" target="_blank"><img class="lightsocial_img" src="http://scratchbox.co.uk/wp-content/plugins/light-social/dotnetshoutout.png" alt="Shout it" title="Shout it" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.linkedin.com/shareArticle?mini=true&amp;url=http%3A%2F%2Fscratchbox.co.uk%2F2012%2F05%2Fchanging-the-colour-scheme-in-excel-2010%2F&amp;title=Changing+the+colour+scheme+in+Excel+2010&amp;summary=&amp;source=" target="_blank"><img class="lightsocial_img" src="http://scratchbox.co.uk/wp-content/plugins/light-social/linkedin.png" alt="Share on LinkedIn" title="Share on LinkedIn" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.technorati.com/faves?add=http%3A%2F%2Fscratchbox.co.uk%2F2012%2F05%2Fchanging-the-colour-scheme-in-excel-2010%2F" target="_blank"><img class="lightsocial_img" src="http://scratchbox.co.uk/wp-content/plugins/light-social/technorati.png" alt="Bookmark this on Technorati" title="Bookmark this on Technorati" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://twitter.com/home?status=Reading+http%3A%2F%2Fscratchbox.co.uk%2F2012%2F05%2Fchanging-the-colour-scheme-in-excel-2010%2F" target="_blank"><img class="lightsocial_img" src="http://scratchbox.co.uk/wp-content/plugins/light-social/twitter.png" alt="Post on Twitter" title="Post on Twitter" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.google.com/buzz/post?url=http%3A%2F%2Fscratchbox.co.uk%2F2012%2F05%2Fchanging-the-colour-scheme-in-excel-2010%2F" target="_blank"><img class="lightsocial_img" src="http://scratchbox.co.uk/wp-content/plugins/light-social/google_buzz.png" alt="Google Buzz (aka. Google Reader)" title="Google Buzz (aka. Google Reader)" /></a>&nbsp;&nbsp;</div>]]></content:encoded>
			<wfw:commentRss>http://scratchbox.co.uk/2012/05/changing-the-colour-scheme-in-excel-2010/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Managing Primary Key Constraints</title>
		<link>http://scratchbox.co.uk/2012/05/managing-primary-key-constraints/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=managing-primary-key-constraints</link>
		<comments>http://scratchbox.co.uk/2012/05/managing-primary-key-constraints/#comments</comments>
		<pubDate>Mon, 14 May 2012 18:27:50 +0000</pubDate>
		<dc:creator>Zach Stagers</dc:creator>
				<category><![CDATA[SQL]]></category>
		<category><![CDATA[Constraints]]></category>
		<category><![CDATA[Data Validation]]></category>
		<category><![CDATA[Primary]]></category>
		<category><![CDATA[Unique]]></category>

		<guid isPermaLink="false">http://scratchbox.co.uk/?p=150</guid>
		<description><![CDATA[Primary Key Constraints keep your rows unique, and therefore help maintain your datas integrity. They can be applied to a single column, or across multiple columns (A maximum of 16). Any column or combination of columns referenced by the Primary &#8230; <a href="http://scratchbox.co.uk/2012/05/managing-primary-key-constraints/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Primary Key Constraints keep your rows unique, and therefore help maintain your datas integrity.</p>
<p>They can be applied to a single column, or across multiple columns (A maximum of 16). Any column or combination of columns referenced by the Primary Key will be unique, and because of this, they’re usually chosen as the Identity column as well.</p>
<p>A Primary Key column cannot be nullable, due to the fact that it forces uniqueness in the table. Computed columns are allowed to be used as a Primary Key.</p>
<p>When a Primary Key is created, the columns it’s created on also have a clustered index created on them. If you’d like to override this functionality, you can do so by specifying NONCLUSTERED during the creation of the key.</p>
<p><strong>Adding a Primary Key Constraint to an existing table</strong></p>

<div class="wp_syntax"><div class="code"><pre class="tsql" style="font-family:monospace;"><span style="color: #0000FF;">ALTER</span> <span style="color: #0000FF;">TABLE</span> Products
<span style="color: #0000FF;">ADD</span> <span style="color: #0000FF;">PRIMARY</span> <span style="color: #0000FF;">KEY</span> <span style="color: #808080;">&#40;</span>ProductId<span style="color: #808080;">&#41;</span></pre></div></div>

<p>The above code will modify the Products table to add a Primary Key Constraint to the ProductId column.</p>

<div class="wp_syntax"><div class="code"><pre class="tsql" style="font-family:monospace;"><span style="color: #0000FF;">ALTER</span> <span style="color: #0000FF;">TABLE</span> Products
<span style="color: #0000FF;">ADD</span> <span style="color: #0000FF;">PRIMARY</span> <span style="color: #0000FF;">KEY</span> <span style="color: #0000FF;">NONCLUSTERED</span> <span style="color: #808080;">&#40;</span>ProductId, ProductName<span style="color: #808080;">&#41;</span></pre></div></div>

<p>The above code will modify the Products table to add a Primary Key Constraint across two columns, but also overrides the default action of creating a clustered composite index, and creates a nonclustered composite index instead. What do I mean by composite? This means that the index references multiple columns.</p>
<p><strong>Adding a Primary Key Constraint during table creation</strong></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> Products 
  <span style="color: #808080;">&#40;</span>
   ProductId <span style="color: #0000FF;">INT</span> <span style="color: #0000FF;">PRIMARY</span> <span style="color: #0000FF;">KEY</span> <span style="color: #0000FF;">IDENTITY</span>,
   ProductName <span style="color: #0000FF;">VARCHAR</span><span style="color: #808080;">&#40;</span><span style="color: #000;">50</span><span style="color: #808080;">&#41;</span><span style="color: #808080;">&#41;</span></pre></div></div>

<p>In the above example, we’re adding the Primary Key to the integer column ProductId. The same column is also being specified as the identity column for the table, as I mentioned earlier, this is fairly common.</p>
<p><strong>Removing a Primary Key Constraint</strong></p>
<p>A table can only ever have one Primary Key, and you may reassess your needs and have to drop the existing Primary Key.</p>
<p>In order to do this, you’ll first need to find the name of the primary key that you’d like to drop. You can do this by executing the below code (replace “Schema.Table” with your details, but keep the single quotes):</p>

<div class="wp_syntax"><div class="code"><pre class="tsql" style="font-family:monospace;"><span style="color: #0000FF;">SELECT</span> I.<span style="color: #202020;">name</span> <span style="color: #808080;">&#91;</span>PrimaryKeyName<span style="color: #808080;">&#93;</span>
&nbsp;
<span style="color: #0000FF;">FROM</span> sys.<span style="color: #202020;">tables</span> T 
     <span style="color: #808080;">JOIN</span> sys.<span style="color: #202020;">indexes</span> I <span style="color: #0000FF;">ON</span> I.<span style="color: #FF00FF;">OBJECT_ID</span> <span style="color: #808080;">=</span> T.<span style="color: #FF00FF;">OBJECT_ID</span>
&nbsp;
<span style="color: #0000FF;">WHERE</span> T.<span style="color: #FF00FF;">OBJECT_ID</span> <span style="color: #808080;">=</span> <span style="color: #FF00FF;">OBJECT_ID</span><span style="color: #808080;">&#40;</span><span style="color: #FF0000;">'Schema.Table'</span><span style="color: #808080;">&#41;</span> 
      <span style="color: #808080;">AND</span> I.<span style="color: #202020;">is_primary_key</span> <span style="color: #808080;">=</span> <span style="color: #000;">1</span></pre></div></div>

<p>Once you’ve run the above code, and the name has been returned, you can run the below code to drop the Primary Key:</p>

<div class="wp_syntax"><div class="code"><pre class="tsql" style="font-family:monospace;"><span style="color: #0000FF;">ALTER</span> <span style="color: #0000FF;">TABLE</span> table_name
<span style="color: #0000FF;">DROP</span> <span style="color: #0000FF;">CONSTRAINT</span> primary_key_constraint_name</pre></div></div>

<div class="lightsocial_container"><a class="lightsocial_a" href="http://digg.com/submit?url=http%3A%2F%2Fscratchbox.co.uk%2F2012%2F05%2Fmanaging-primary-key-constraints%2F&amp;title=Managing+Primary+Key+Constraints" target="_blank"><img class="lightsocial_img" src="http://scratchbox.co.uk/wp-content/plugins/light-social/digg.png" alt="Digg This" title="Digg This" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.reddit.com/submit?url=http%3A%2F%2Fscratchbox.co.uk%2F2012%2F05%2Fmanaging-primary-key-constraints%2F&amp;title=Managing+Primary+Key+Constraints" target="_blank"><img class="lightsocial_img" src="http://scratchbox.co.uk/wp-content/plugins/light-social/reddit.png" alt="Reddit This" title="Reddit This" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.stumbleupon.com/submit?url=http%3A%2F%2Fscratchbox.co.uk%2F2012%2F05%2Fmanaging-primary-key-constraints%2F&amp;title=Managing+Primary+Key+Constraints" target="_blank"><img class="lightsocial_img" src="http://scratchbox.co.uk/wp-content/plugins/light-social/stumbleupon.png" alt="Stumble Now!" title="Stumble Now!" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://buzz.yahoo.com/buzz?targetUrl=http%3A%2F%2Fscratchbox.co.uk%2F2012%2F05%2Fmanaging-primary-key-constraints%2F&amp;headline=Managing+Primary+Key+Constraints" target="_blank"><img class="lightsocial_img" src="http://scratchbox.co.uk/wp-content/plugins/light-social/yahoo_buzz.png" alt="Buzz This" title="Buzz This" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.dzone.com/links/add.html?title=Managing+Primary+Key+Constraints&amp;url=http%3A%2F%2Fscratchbox.co.uk%2F2012%2F05%2Fmanaging-primary-key-constraints%2F" target="_blank"><img class="lightsocial_img" src="http://scratchbox.co.uk/wp-content/plugins/light-social/dzone.png" alt="Vote on DZone" title="Vote on DZone" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.facebook.com/sharer.php?t=Managing+Primary+Key+Constraints&amp;u=http%3A%2F%2Fscratchbox.co.uk%2F2012%2F05%2Fmanaging-primary-key-constraints%2F" target="_blank"><img class="lightsocial_img" src="http://scratchbox.co.uk/wp-content/plugins/light-social/facebook.png" alt="Share on Facebook" title="Share on Facebook" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://delicious.com/save?title=Managing+Primary+Key+Constraints&amp;url=http%3A%2F%2Fscratchbox.co.uk%2F2012%2F05%2Fmanaging-primary-key-constraints%2F" target="_blank"><img class="lightsocial_img" src="http://scratchbox.co.uk/wp-content/plugins/light-social/delicious.png" alt="Bookmark this on Delicious" title="Bookmark this on Delicious" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.dotnetkicks.com/kick/?title=Managing+Primary+Key+Constraints&amp;url=http%3A%2F%2Fscratchbox.co.uk%2F2012%2F05%2Fmanaging-primary-key-constraints%2F" target="_blank"><img class="lightsocial_img" src="http://scratchbox.co.uk/wp-content/plugins/light-social/dotnetkicks.png" alt="Kick It on DotNetKicks.com" title="Kick It on DotNetKicks.com" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://dotnetshoutout.com/Submit?title=Managing+Primary+Key+Constraints&amp;url=http%3A%2F%2Fscratchbox.co.uk%2F2012%2F05%2Fmanaging-primary-key-constraints%2F" target="_blank"><img class="lightsocial_img" src="http://scratchbox.co.uk/wp-content/plugins/light-social/dotnetshoutout.png" alt="Shout it" title="Shout it" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.linkedin.com/shareArticle?mini=true&amp;url=http%3A%2F%2Fscratchbox.co.uk%2F2012%2F05%2Fmanaging-primary-key-constraints%2F&amp;title=Managing+Primary+Key+Constraints&amp;summary=&amp;source=" target="_blank"><img class="lightsocial_img" src="http://scratchbox.co.uk/wp-content/plugins/light-social/linkedin.png" alt="Share on LinkedIn" title="Share on LinkedIn" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.technorati.com/faves?add=http%3A%2F%2Fscratchbox.co.uk%2F2012%2F05%2Fmanaging-primary-key-constraints%2F" target="_blank"><img class="lightsocial_img" src="http://scratchbox.co.uk/wp-content/plugins/light-social/technorati.png" alt="Bookmark this on Technorati" title="Bookmark this on Technorati" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://twitter.com/home?status=Reading+http%3A%2F%2Fscratchbox.co.uk%2F2012%2F05%2Fmanaging-primary-key-constraints%2F" target="_blank"><img class="lightsocial_img" src="http://scratchbox.co.uk/wp-content/plugins/light-social/twitter.png" alt="Post on Twitter" title="Post on Twitter" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.google.com/buzz/post?url=http%3A%2F%2Fscratchbox.co.uk%2F2012%2F05%2Fmanaging-primary-key-constraints%2F" target="_blank"><img class="lightsocial_img" src="http://scratchbox.co.uk/wp-content/plugins/light-social/google_buzz.png" alt="Google Buzz (aka. Google Reader)" title="Google Buzz (aka. Google Reader)" /></a>&nbsp;&nbsp;</div>]]></content:encoded>
			<wfw:commentRss>http://scratchbox.co.uk/2012/05/managing-primary-key-constraints/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Case Statements</title>
		<link>http://scratchbox.co.uk/2012/05/case-statements/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=case-statements</link>
		<comments>http://scratchbox.co.uk/2012/05/case-statements/#comments</comments>
		<pubDate>Mon, 14 May 2012 14:23:46 +0000</pubDate>
		<dc:creator>Zach Stagers</dc:creator>
				<category><![CDATA[SQL]]></category>
		<category><![CDATA[Case]]></category>
		<category><![CDATA[Then]]></category>
		<category><![CDATA[When]]></category>

		<guid isPermaLink="false">http://scratchbox.co.uk/?p=145</guid>
		<description><![CDATA[Case Statements are used to output different data depending on the value returned from a column: CASE WHEN Column1 = 'Seven' THEN 7 WHEN Column1 = 'Eight' THEN 8 ELSE 0 END AS &#91;Number&#93; The above syntax would be used &#8230; <a href="http://scratchbox.co.uk/2012/05/case-statements/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Case Statements are used to output different data depending on the value returned from a column:</p>

<div class="wp_syntax"><div class="code"><pre class="tsql" style="font-family:monospace;"><span style="color: #0000FF;">CASE</span>
 <span style="color: #0000FF;">WHEN</span> Column1 <span style="color: #808080;">=</span> <span style="color: #FF0000;">'Seven'</span> <span style="color: #0000FF;">THEN</span> <span style="color: #000;">7</span>
 <span style="color: #0000FF;">WHEN</span> Column1 <span style="color: #808080;">=</span> <span style="color: #FF0000;">'Eight'</span> <span style="color: #0000FF;">THEN</span> <span style="color: #000;">8</span>
 <span style="color: #0000FF;">ELSE</span> <span style="color: #000;">0</span>
 <span style="color: #0000FF;">END</span> <span style="color: #0000FF;">AS</span> <span style="color: #808080;">&#91;</span>Number<span style="color: #808080;">&#93;</span></pre></div></div>

<p>The above syntax would be used within a select statement, and would be placed along side all other columns in your column list. This example would check all data returned from Column1, if it finds the word ‘Seven’ then the number 7 will be returned in its place, the same goes for ‘Eight’ and 8. Anything that does not equal ‘Seven’ or ‘Eight’ will be returned as a 0.</p>
<p>As many WHEN lines can be written as are necessary.</p>
<p>It’s possible to nest Case statements up to a maximum of 10 levels deep.</p>
<p>Case Statements can also be used within Where clauses, which is particulary useful within a parameterized stored procedure.</p>
<p>For example, if you had a parameter of @Cost, then your Where clause may look like this:</p>

<div class="wp_syntax"><div class="code"><pre class="tsql" style="font-family:monospace;"><span style="color: #0000FF;">WHERE</span> <span style="color: #0000FF;">CASE</span>
       <span style="color: #0000FF;">WHEN</span> @Cost <span style="color: #808080;">=</span> <span style="color: #FF0000;">'All'</span> <span style="color: #0000FF;">THEN</span> <span style="color: #000;">1</span>
       <span style="color: #0000FF;">WHEN</span> @Cost <span style="color: #808080;">=</span> <span style="color: #FF0000;">'None'</span> <span style="color: #808080;">AND</span> Column1 <span style="color: #0000FF;">IS</span> <span style="color: #808080;">NULL</span> <span style="color: #0000FF;">THEN</span> <span style="color: #000;">1</span>
       <span style="color: #0000FF;">WHEN</span> @Cost <span style="color: #808080;">NOT</span> <span style="color: #808080;">IN</span> <span style="color: #808080;">&#40;</span><span style="color: #FF0000;">'All'</span>, <span style="color: #FF0000;">'None'</span><span style="color: #808080;">&#41;</span> <span style="color: #808080;">AND</span> Column1 <span style="color: #808080;">=</span> <span style="color: #0000FF;">CONVERT</span><span style="color: #808080;">&#40;</span><span style="color: #0000FF;">INT</span>, @Cost<span style="color: #808080;">&#41;</span> <span style="color: #0000FF;">THEN</span> <span style="color: #000;">1</span>
       <span style="color: #0000FF;">ELSE</span> <span style="color: #000;">0</span>
       <span style="color: #0000FF;">END</span> <span style="color: #808080;">=</span> <span style="color: #000;">1</span></pre></div></div>

<p>The above example is checking the value of our Varchar parameter @Cost, then performing any search functionality that goes along with it.</p>
<p>When @Cost is All, there is no other search critiria written as we want to return everything. When @Cost is None, then we only want to return columns with a NULL entry, so we check that @Cost is ‘None’ and our Column1 IS NULL.</p>
<p>When we want to work with the @Cost parameter as an INT, we have to explicitly define that it’s not All or None, then specify our search “Column1 = Covert(INT, @Cost)”. If we do not explicitly define that we are no longer searching for All or None within @Cost, an error will occur for trying to compare an Int and a Varchar value.</p>
<p>The last use of the CASE statement that I’d like to mention is within an UPDATE statement. You can use the CASE to define what value should be set depending on the value of another column, for example:</p>

<div class="wp_syntax"><div class="code"><pre class="tsql" style="font-family:monospace;"><span style="color: #0000FF;">UPDATE</span> Table1
<span style="color: #0000FF;">SET</span> Column1 <span style="color: #808080;">=</span> <span style="color: #0000FF;">CASE</span> 
               <span style="color: #0000FF;">WHEN</span> Column2 <span style="color: #808080;">=</span> <span style="color: #FF0000;">'Seven'</span> <span style="color: #0000FF;">THEN</span> <span style="color: #000;">7</span>
               <span style="color: #0000FF;">WHEN</span> Column2 <span style="color: #808080;">=</span> <span style="color: #FF0000;">'Eight'</span> <span style="color: #0000FF;">THEN</span> <span style="color: #000;">8</span>
               <span style="color: #0000FF;">END</span>
<span style="color: #0000FF;">WHERE</span> Column1 <span style="color: #0000FF;">IS</span> <span style="color: #808080;">NULL</span></pre></div></div>

<div class="lightsocial_container"><a class="lightsocial_a" href="http://digg.com/submit?url=http%3A%2F%2Fscratchbox.co.uk%2F2012%2F05%2Fcase-statements%2F&amp;title=Case+Statements" target="_blank"><img class="lightsocial_img" src="http://scratchbox.co.uk/wp-content/plugins/light-social/digg.png" alt="Digg This" title="Digg This" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.reddit.com/submit?url=http%3A%2F%2Fscratchbox.co.uk%2F2012%2F05%2Fcase-statements%2F&amp;title=Case+Statements" target="_blank"><img class="lightsocial_img" src="http://scratchbox.co.uk/wp-content/plugins/light-social/reddit.png" alt="Reddit This" title="Reddit This" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.stumbleupon.com/submit?url=http%3A%2F%2Fscratchbox.co.uk%2F2012%2F05%2Fcase-statements%2F&amp;title=Case+Statements" target="_blank"><img class="lightsocial_img" src="http://scratchbox.co.uk/wp-content/plugins/light-social/stumbleupon.png" alt="Stumble Now!" title="Stumble Now!" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://buzz.yahoo.com/buzz?targetUrl=http%3A%2F%2Fscratchbox.co.uk%2F2012%2F05%2Fcase-statements%2F&amp;headline=Case+Statements" target="_blank"><img class="lightsocial_img" src="http://scratchbox.co.uk/wp-content/plugins/light-social/yahoo_buzz.png" alt="Buzz This" title="Buzz This" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.dzone.com/links/add.html?title=Case+Statements&amp;url=http%3A%2F%2Fscratchbox.co.uk%2F2012%2F05%2Fcase-statements%2F" target="_blank"><img class="lightsocial_img" src="http://scratchbox.co.uk/wp-content/plugins/light-social/dzone.png" alt="Vote on DZone" title="Vote on DZone" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.facebook.com/sharer.php?t=Case+Statements&amp;u=http%3A%2F%2Fscratchbox.co.uk%2F2012%2F05%2Fcase-statements%2F" target="_blank"><img class="lightsocial_img" src="http://scratchbox.co.uk/wp-content/plugins/light-social/facebook.png" alt="Share on Facebook" title="Share on Facebook" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://delicious.com/save?title=Case+Statements&amp;url=http%3A%2F%2Fscratchbox.co.uk%2F2012%2F05%2Fcase-statements%2F" target="_blank"><img class="lightsocial_img" src="http://scratchbox.co.uk/wp-content/plugins/light-social/delicious.png" alt="Bookmark this on Delicious" title="Bookmark this on Delicious" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.dotnetkicks.com/kick/?title=Case+Statements&amp;url=http%3A%2F%2Fscratchbox.co.uk%2F2012%2F05%2Fcase-statements%2F" target="_blank"><img class="lightsocial_img" src="http://scratchbox.co.uk/wp-content/plugins/light-social/dotnetkicks.png" alt="Kick It on DotNetKicks.com" title="Kick It on DotNetKicks.com" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://dotnetshoutout.com/Submit?title=Case+Statements&amp;url=http%3A%2F%2Fscratchbox.co.uk%2F2012%2F05%2Fcase-statements%2F" target="_blank"><img class="lightsocial_img" src="http://scratchbox.co.uk/wp-content/plugins/light-social/dotnetshoutout.png" alt="Shout it" title="Shout it" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.linkedin.com/shareArticle?mini=true&amp;url=http%3A%2F%2Fscratchbox.co.uk%2F2012%2F05%2Fcase-statements%2F&amp;title=Case+Statements&amp;summary=&amp;source=" target="_blank"><img class="lightsocial_img" src="http://scratchbox.co.uk/wp-content/plugins/light-social/linkedin.png" alt="Share on LinkedIn" title="Share on LinkedIn" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.technorati.com/faves?add=http%3A%2F%2Fscratchbox.co.uk%2F2012%2F05%2Fcase-statements%2F" target="_blank"><img class="lightsocial_img" src="http://scratchbox.co.uk/wp-content/plugins/light-social/technorati.png" alt="Bookmark this on Technorati" title="Bookmark this on Technorati" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://twitter.com/home?status=Reading+http%3A%2F%2Fscratchbox.co.uk%2F2012%2F05%2Fcase-statements%2F" target="_blank"><img class="lightsocial_img" src="http://scratchbox.co.uk/wp-content/plugins/light-social/twitter.png" alt="Post on Twitter" title="Post on Twitter" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.google.com/buzz/post?url=http%3A%2F%2Fscratchbox.co.uk%2F2012%2F05%2Fcase-statements%2F" target="_blank"><img class="lightsocial_img" src="http://scratchbox.co.uk/wp-content/plugins/light-social/google_buzz.png" alt="Google Buzz (aka. Google Reader)" title="Google Buzz (aka. Google Reader)" /></a>&nbsp;&nbsp;</div>]]></content:encoded>
			<wfw:commentRss>http://scratchbox.co.uk/2012/05/case-statements/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Keyboard Shortcut to Upper or Lower Case Code in SSMS</title>
		<link>http://scratchbox.co.uk/2012/05/keyboard-shortcut-to-upper-or-lower-case-code-in-ssms/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=keyboard-shortcut-to-upper-or-lower-case-code-in-ssms</link>
		<comments>http://scratchbox.co.uk/2012/05/keyboard-shortcut-to-upper-or-lower-case-code-in-ssms/#comments</comments>
		<pubDate>Mon, 14 May 2012 11:22:41 +0000</pubDate>
		<dc:creator>Zach Stagers</dc:creator>
				<category><![CDATA[SQL Server Management Studio]]></category>
		<category><![CDATA[Keyboard Shortcut]]></category>
		<category><![CDATA[Lower]]></category>
		<category><![CDATA[Upper]]></category>

		<guid isPermaLink="false">http://scratchbox.co.uk/?p=142</guid>
		<description><![CDATA[If, like me, you like your code to be formatted in a specific way, then this little shortcut may save you a bit of time when you need to pick up and modify someone elses code. For example, I like &#8230; <a href="http://scratchbox.co.uk/2012/05/keyboard-shortcut-to-upper-or-lower-case-code-in-ssms/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>If, like me, you like your code to be formatted in a specific way, then this little shortcut may save you a bit of time when you need to pick up and modify someone elses code.</p>
<p>For example, I like all of my SQL keywords to be written in upper case letters, so if I find one that isn’t in a colleagues code – I simply highlight the text with my cursor then press CTRL + SHIFT + U to make all of the letters upper case.</p>
<p>The reverse of this, should you ever need to make letters lower case is CTRL + SHIFT + L.</p>
<div class="lightsocial_container"><a class="lightsocial_a" href="http://digg.com/submit?url=http%3A%2F%2Fscratchbox.co.uk%2F2012%2F05%2Fkeyboard-shortcut-to-upper-or-lower-case-code-in-ssms%2F&amp;title=Keyboard+Shortcut+to+Upper+or+Lower+Case+Code+in+SSMS" target="_blank"><img class="lightsocial_img" src="http://scratchbox.co.uk/wp-content/plugins/light-social/digg.png" alt="Digg This" title="Digg This" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.reddit.com/submit?url=http%3A%2F%2Fscratchbox.co.uk%2F2012%2F05%2Fkeyboard-shortcut-to-upper-or-lower-case-code-in-ssms%2F&amp;title=Keyboard+Shortcut+to+Upper+or+Lower+Case+Code+in+SSMS" target="_blank"><img class="lightsocial_img" src="http://scratchbox.co.uk/wp-content/plugins/light-social/reddit.png" alt="Reddit This" title="Reddit This" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.stumbleupon.com/submit?url=http%3A%2F%2Fscratchbox.co.uk%2F2012%2F05%2Fkeyboard-shortcut-to-upper-or-lower-case-code-in-ssms%2F&amp;title=Keyboard+Shortcut+to+Upper+or+Lower+Case+Code+in+SSMS" target="_blank"><img class="lightsocial_img" src="http://scratchbox.co.uk/wp-content/plugins/light-social/stumbleupon.png" alt="Stumble Now!" title="Stumble Now!" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://buzz.yahoo.com/buzz?targetUrl=http%3A%2F%2Fscratchbox.co.uk%2F2012%2F05%2Fkeyboard-shortcut-to-upper-or-lower-case-code-in-ssms%2F&amp;headline=Keyboard+Shortcut+to+Upper+or+Lower+Case+Code+in+SSMS" target="_blank"><img class="lightsocial_img" src="http://scratchbox.co.uk/wp-content/plugins/light-social/yahoo_buzz.png" alt="Buzz This" title="Buzz This" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.dzone.com/links/add.html?title=Keyboard+Shortcut+to+Upper+or+Lower+Case+Code+in+SSMS&amp;url=http%3A%2F%2Fscratchbox.co.uk%2F2012%2F05%2Fkeyboard-shortcut-to-upper-or-lower-case-code-in-ssms%2F" target="_blank"><img class="lightsocial_img" src="http://scratchbox.co.uk/wp-content/plugins/light-social/dzone.png" alt="Vote on DZone" title="Vote on DZone" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.facebook.com/sharer.php?t=Keyboard+Shortcut+to+Upper+or+Lower+Case+Code+in+SSMS&amp;u=http%3A%2F%2Fscratchbox.co.uk%2F2012%2F05%2Fkeyboard-shortcut-to-upper-or-lower-case-code-in-ssms%2F" target="_blank"><img class="lightsocial_img" src="http://scratchbox.co.uk/wp-content/plugins/light-social/facebook.png" alt="Share on Facebook" title="Share on Facebook" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://delicious.com/save?title=Keyboard+Shortcut+to+Upper+or+Lower+Case+Code+in+SSMS&amp;url=http%3A%2F%2Fscratchbox.co.uk%2F2012%2F05%2Fkeyboard-shortcut-to-upper-or-lower-case-code-in-ssms%2F" target="_blank"><img class="lightsocial_img" src="http://scratchbox.co.uk/wp-content/plugins/light-social/delicious.png" alt="Bookmark this on Delicious" title="Bookmark this on Delicious" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.dotnetkicks.com/kick/?title=Keyboard+Shortcut+to+Upper+or+Lower+Case+Code+in+SSMS&amp;url=http%3A%2F%2Fscratchbox.co.uk%2F2012%2F05%2Fkeyboard-shortcut-to-upper-or-lower-case-code-in-ssms%2F" target="_blank"><img class="lightsocial_img" src="http://scratchbox.co.uk/wp-content/plugins/light-social/dotnetkicks.png" alt="Kick It on DotNetKicks.com" title="Kick It on DotNetKicks.com" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://dotnetshoutout.com/Submit?title=Keyboard+Shortcut+to+Upper+or+Lower+Case+Code+in+SSMS&amp;url=http%3A%2F%2Fscratchbox.co.uk%2F2012%2F05%2Fkeyboard-shortcut-to-upper-or-lower-case-code-in-ssms%2F" target="_blank"><img class="lightsocial_img" src="http://scratchbox.co.uk/wp-content/plugins/light-social/dotnetshoutout.png" alt="Shout it" title="Shout it" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.linkedin.com/shareArticle?mini=true&amp;url=http%3A%2F%2Fscratchbox.co.uk%2F2012%2F05%2Fkeyboard-shortcut-to-upper-or-lower-case-code-in-ssms%2F&amp;title=Keyboard+Shortcut+to+Upper+or+Lower+Case+Code+in+SSMS&amp;summary=&amp;source=" target="_blank"><img class="lightsocial_img" src="http://scratchbox.co.uk/wp-content/plugins/light-social/linkedin.png" alt="Share on LinkedIn" title="Share on LinkedIn" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.technorati.com/faves?add=http%3A%2F%2Fscratchbox.co.uk%2F2012%2F05%2Fkeyboard-shortcut-to-upper-or-lower-case-code-in-ssms%2F" target="_blank"><img class="lightsocial_img" src="http://scratchbox.co.uk/wp-content/plugins/light-social/technorati.png" alt="Bookmark this on Technorati" title="Bookmark this on Technorati" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://twitter.com/home?status=Reading+http%3A%2F%2Fscratchbox.co.uk%2F2012%2F05%2Fkeyboard-shortcut-to-upper-or-lower-case-code-in-ssms%2F" target="_blank"><img class="lightsocial_img" src="http://scratchbox.co.uk/wp-content/plugins/light-social/twitter.png" alt="Post on Twitter" title="Post on Twitter" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.google.com/buzz/post?url=http%3A%2F%2Fscratchbox.co.uk%2F2012%2F05%2Fkeyboard-shortcut-to-upper-or-lower-case-code-in-ssms%2F" target="_blank"><img class="lightsocial_img" src="http://scratchbox.co.uk/wp-content/plugins/light-social/google_buzz.png" alt="Google Buzz (aka. Google Reader)" title="Google Buzz (aka. Google Reader)" /></a>&nbsp;&nbsp;</div>]]></content:encoded>
			<wfw:commentRss>http://scratchbox.co.uk/2012/05/keyboard-shortcut-to-upper-or-lower-case-code-in-ssms/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Finding Distinct Values in Excel 2010</title>
		<link>http://scratchbox.co.uk/2012/05/finding-distinct-values-in-excel-2010/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=finding-distinct-values-in-excel-2010</link>
		<comments>http://scratchbox.co.uk/2012/05/finding-distinct-values-in-excel-2010/#comments</comments>
		<pubDate>Sun, 13 May 2012 21:01:28 +0000</pubDate>
		<dc:creator>Zach Stagers</dc:creator>
				<category><![CDATA[Microsoft Excel]]></category>
		<category><![CDATA[Conditional Formatting]]></category>
		<category><![CDATA[Duplicates]]></category>
		<category><![CDATA[Excel]]></category>

		<guid isPermaLink="false">http://scratchbox.co.uk/?p=129</guid>
		<description><![CDATA[This is something that I’ve just found myself, and I wish I would have known about it a few days ago when I was asked to extract a distinct list of values from a column. Start off by highlighting the &#8230; <a href="http://scratchbox.co.uk/2012/05/finding-distinct-values-in-excel-2010/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>This is something that I’ve just found myself, and I wish I would have known about it a few days ago when I was asked to extract a distinct list of values from a column.</p>
<p>Start off by highlighting the range of data that you would like to find the distinct values in, I’ll be using the below simple sample data for the purpose of this post:</p>
<div id="attachment_130" class="wp-caption alignnone" style="width: 154px"><img src="http://scratchbox.co.uk/wp-content/uploads/2012/05/1_Example-Data.jpg" alt="Example Data" title="Example Data" width="144" height="194" class="size-full wp-image-130" /><p class="wp-caption-text">Example Data</p></div>
<p>On the “Data” tab of Excel 2010, find the “Remove Duplicates” button:</p>
<p><img src="http://scratchbox.co.uk/wp-content/uploads/2012/05/2_Remove-Duplicates-Button.jpg" alt="Remove Duplicates Button" title="Remove Duplicates Button" width="66" height="73" class="size-full wp-image-131" /></p>
<p>Click the button, and the Remove Duplicates Dialogue will appear:</p>
<div id="attachment_132" class="wp-caption alignnone" style="width: 460px"><img src="http://scratchbox.co.uk/wp-content/uploads/2012/05/3_Remove-Duplicates-Dialogue.jpg" alt="Remove Duplicates Dialogue" title="Remove Duplicates Dialogue" width="450" height="283" class="size-full wp-image-132" /><p class="wp-caption-text">Remove Duplicates Dialogue</p></div>
<p>On the top right of the Remove Duplicates Dialogue box, you’ll see a check box – “My data has headers” – you can toggle this check box depending on whether or not you have headers in your data. I’m going to leave it checked for the purpose of this example. The check box “Column” is the name of the column I’m removing duplicates from, if multiple columns are selected in the first step – they can be managed from here.</p>
<p>Once you’re ready, click OK, and the below message will appear – giving you a few details about what has occurred:</p>
<div id="attachment_135" class="wp-caption alignnone" style="width: 409px"><img src="http://scratchbox.co.uk/wp-content/uploads/2012/05/4_Remove-Duplicates-Message-Box1.jpg" alt="Remove Duplicates Message Box" title="Remove Duplicates Message Box" width="399" height="147" class="size-full wp-image-135" /><p class="wp-caption-text">Remove Duplicates Message Box</p></div>
<p>The result:</p>
<div id="attachment_136" class="wp-caption alignnone" style="width: 150px"><img src="http://scratchbox.co.uk/wp-content/uploads/2012/05/5_Remove-Duplicates-Result.jpg" alt="Remove Duplicates Result" title="Remove Duplicates Result" width="140" height="154" class="size-full wp-image-136" /><p class="wp-caption-text">Remove Duplicates Result</p></div>
<div class="lightsocial_container"><a class="lightsocial_a" href="http://digg.com/submit?url=http%3A%2F%2Fscratchbox.co.uk%2F2012%2F05%2Ffinding-distinct-values-in-excel-2010%2F&amp;title=Finding+Distinct+Values+in+Excel+2010" target="_blank"><img class="lightsocial_img" src="http://scratchbox.co.uk/wp-content/plugins/light-social/digg.png" alt="Digg This" title="Digg This" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.reddit.com/submit?url=http%3A%2F%2Fscratchbox.co.uk%2F2012%2F05%2Ffinding-distinct-values-in-excel-2010%2F&amp;title=Finding+Distinct+Values+in+Excel+2010" target="_blank"><img class="lightsocial_img" src="http://scratchbox.co.uk/wp-content/plugins/light-social/reddit.png" alt="Reddit This" title="Reddit This" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.stumbleupon.com/submit?url=http%3A%2F%2Fscratchbox.co.uk%2F2012%2F05%2Ffinding-distinct-values-in-excel-2010%2F&amp;title=Finding+Distinct+Values+in+Excel+2010" target="_blank"><img class="lightsocial_img" src="http://scratchbox.co.uk/wp-content/plugins/light-social/stumbleupon.png" alt="Stumble Now!" title="Stumble Now!" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://buzz.yahoo.com/buzz?targetUrl=http%3A%2F%2Fscratchbox.co.uk%2F2012%2F05%2Ffinding-distinct-values-in-excel-2010%2F&amp;headline=Finding+Distinct+Values+in+Excel+2010" target="_blank"><img class="lightsocial_img" src="http://scratchbox.co.uk/wp-content/plugins/light-social/yahoo_buzz.png" alt="Buzz This" title="Buzz This" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.dzone.com/links/add.html?title=Finding+Distinct+Values+in+Excel+2010&amp;url=http%3A%2F%2Fscratchbox.co.uk%2F2012%2F05%2Ffinding-distinct-values-in-excel-2010%2F" target="_blank"><img class="lightsocial_img" src="http://scratchbox.co.uk/wp-content/plugins/light-social/dzone.png" alt="Vote on DZone" title="Vote on DZone" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.facebook.com/sharer.php?t=Finding+Distinct+Values+in+Excel+2010&amp;u=http%3A%2F%2Fscratchbox.co.uk%2F2012%2F05%2Ffinding-distinct-values-in-excel-2010%2F" target="_blank"><img class="lightsocial_img" src="http://scratchbox.co.uk/wp-content/plugins/light-social/facebook.png" alt="Share on Facebook" title="Share on Facebook" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://delicious.com/save?title=Finding+Distinct+Values+in+Excel+2010&amp;url=http%3A%2F%2Fscratchbox.co.uk%2F2012%2F05%2Ffinding-distinct-values-in-excel-2010%2F" target="_blank"><img class="lightsocial_img" src="http://scratchbox.co.uk/wp-content/plugins/light-social/delicious.png" alt="Bookmark this on Delicious" title="Bookmark this on Delicious" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.dotnetkicks.com/kick/?title=Finding+Distinct+Values+in+Excel+2010&amp;url=http%3A%2F%2Fscratchbox.co.uk%2F2012%2F05%2Ffinding-distinct-values-in-excel-2010%2F" target="_blank"><img class="lightsocial_img" src="http://scratchbox.co.uk/wp-content/plugins/light-social/dotnetkicks.png" alt="Kick It on DotNetKicks.com" title="Kick It on DotNetKicks.com" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://dotnetshoutout.com/Submit?title=Finding+Distinct+Values+in+Excel+2010&amp;url=http%3A%2F%2Fscratchbox.co.uk%2F2012%2F05%2Ffinding-distinct-values-in-excel-2010%2F" target="_blank"><img class="lightsocial_img" src="http://scratchbox.co.uk/wp-content/plugins/light-social/dotnetshoutout.png" alt="Shout it" title="Shout it" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.linkedin.com/shareArticle?mini=true&amp;url=http%3A%2F%2Fscratchbox.co.uk%2F2012%2F05%2Ffinding-distinct-values-in-excel-2010%2F&amp;title=Finding+Distinct+Values+in+Excel+2010&amp;summary=&amp;source=" target="_blank"><img class="lightsocial_img" src="http://scratchbox.co.uk/wp-content/plugins/light-social/linkedin.png" alt="Share on LinkedIn" title="Share on LinkedIn" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.technorati.com/faves?add=http%3A%2F%2Fscratchbox.co.uk%2F2012%2F05%2Ffinding-distinct-values-in-excel-2010%2F" target="_blank"><img class="lightsocial_img" src="http://scratchbox.co.uk/wp-content/plugins/light-social/technorati.png" alt="Bookmark this on Technorati" title="Bookmark this on Technorati" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://twitter.com/home?status=Reading+http%3A%2F%2Fscratchbox.co.uk%2F2012%2F05%2Ffinding-distinct-values-in-excel-2010%2F" target="_blank"><img class="lightsocial_img" src="http://scratchbox.co.uk/wp-content/plugins/light-social/twitter.png" alt="Post on Twitter" title="Post on Twitter" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.google.com/buzz/post?url=http%3A%2F%2Fscratchbox.co.uk%2F2012%2F05%2Ffinding-distinct-values-in-excel-2010%2F" target="_blank"><img class="lightsocial_img" src="http://scratchbox.co.uk/wp-content/plugins/light-social/google_buzz.png" alt="Google Buzz (aka. Google Reader)" title="Google Buzz (aka. Google Reader)" /></a>&nbsp;&nbsp;</div>]]></content:encoded>
			<wfw:commentRss>http://scratchbox.co.uk/2012/05/finding-distinct-values-in-excel-2010/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Output Into – Audit Trails</title>
		<link>http://scratchbox.co.uk/2012/05/output-into-audit-trails/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=output-into-audit-trails</link>
		<comments>http://scratchbox.co.uk/2012/05/output-into-audit-trails/#comments</comments>
		<pubDate>Sun, 13 May 2012 20:59:44 +0000</pubDate>
		<dc:creator>Zach Stagers</dc:creator>
				<category><![CDATA[SQL]]></category>
		<category><![CDATA[Audit]]></category>
		<category><![CDATA[Output]]></category>
		<category><![CDATA[Output Into]]></category>

		<guid isPermaLink="false">http://scratchbox.co.uk/?p=126</guid>
		<description><![CDATA[Output &#038; Output Into can be used to track the details of data that’s inserted, updated, or deleted. Ouput is a “simplified” version of Output Into. Output will simply print the results to screen, where as Output Into will insert &#8230; <a href="http://scratchbox.co.uk/2012/05/output-into-audit-trails/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Output &#038; Output Into can be used to track the details of data that’s inserted, updated, or deleted.</p>
<p>Ouput is a “simplified” version of Output Into. Output will simply print the results to screen, where as Output Into will insert the results into a specified table.</p>
<p>These keywords have access to two sytem tables, inserted and deleted. The inserted table contains all data that is added, anything inserted into a table with an insert statement, or the new data added within an update statement. The deleted table holds the opposite, anything removed with a delete statement, or anything overwritten with an update statement.</p>
<p>The below examples show how to use the Output clause with a Delete, Insert, and Update Statement.</p>

<div class="wp_syntax"><div class="code"><pre class="tsql" style="font-family:monospace;"><span style="color: #0000FF;">DELETE</span> <span style="color: #0000FF;">FROM</span> Person
<span style="color: #0000FF;">OUTPUT</span> deleted.<span style="color: #202020;">PersonId</span>, deleted.<span style="color: #202020;">Name</span> <span style="color: #0000FF;">INTO</span> PersonAudit
<span style="color: #0000FF;">WHERE</span> PersonId <span style="color: #808080;">=</span> <span style="color: #000;">73</span></pre></div></div>


<div class="wp_syntax"><div class="code"><pre class="tsql" style="font-family:monospace;"><span style="color: #0000FF;">INSERT</span> <span style="color: #0000FF;">INTO</span> Person
<span style="color: #0000FF;">OUTPUT</span> inserted.<span style="color: #202020;">PersonId</span> inserted.<span style="color: #202020;">Name</span> <span style="color: #0000FF;">INTO</span> PersonAudit
<span style="color: #0000FF;">VALUES</span><span style="color: #808080;">&#40;</span><span style="color: #FF0000;">'Zach Stagers'</span><span style="color: #808080;">&#41;</span></pre></div></div>


<div class="wp_syntax"><div class="code"><pre class="tsql" style="font-family:monospace;"><span style="color: #0000FF;">UPDATE</span> Person
<span style="color: #0000FF;">SET</span> Name <span style="color: #808080;">=</span> <span style="color: #FF0000;">'Zach Stagers'</span>
<span style="color: #0000FF;">OUTPUT</span> inserted.<span style="color: #202020;">PersonId</span>, inserted.<span style="color: #202020;">Name</span>, deleted.<span style="color: #202020;">Name</span> <span style="color: #0000FF;">INTO</span> PersonAudit
<span style="color: #0000FF;">WHERE</span> PersonId <span style="color: #808080;">=</span> <span style="color: #000;">88</span></pre></div></div>

<p>With each of the above examples, remove INTO PersonAudit to use the simplified version mentioned earlier, and just print the results to screen.</p>
<p>With a little bit of planning and correct use of the Output Into clause, you have the ability to create a very useful audit trail.</p>
<div class="lightsocial_container"><a class="lightsocial_a" href="http://digg.com/submit?url=http%3A%2F%2Fscratchbox.co.uk%2F2012%2F05%2Foutput-into-audit-trails%2F&amp;title=Output+Into+%E2%80%93+Audit+Trails" target="_blank"><img class="lightsocial_img" src="http://scratchbox.co.uk/wp-content/plugins/light-social/digg.png" alt="Digg This" title="Digg This" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.reddit.com/submit?url=http%3A%2F%2Fscratchbox.co.uk%2F2012%2F05%2Foutput-into-audit-trails%2F&amp;title=Output+Into+%E2%80%93+Audit+Trails" target="_blank"><img class="lightsocial_img" src="http://scratchbox.co.uk/wp-content/plugins/light-social/reddit.png" alt="Reddit This" title="Reddit This" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.stumbleupon.com/submit?url=http%3A%2F%2Fscratchbox.co.uk%2F2012%2F05%2Foutput-into-audit-trails%2F&amp;title=Output+Into+%E2%80%93+Audit+Trails" target="_blank"><img class="lightsocial_img" src="http://scratchbox.co.uk/wp-content/plugins/light-social/stumbleupon.png" alt="Stumble Now!" title="Stumble Now!" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://buzz.yahoo.com/buzz?targetUrl=http%3A%2F%2Fscratchbox.co.uk%2F2012%2F05%2Foutput-into-audit-trails%2F&amp;headline=Output+Into+%E2%80%93+Audit+Trails" target="_blank"><img class="lightsocial_img" src="http://scratchbox.co.uk/wp-content/plugins/light-social/yahoo_buzz.png" alt="Buzz This" title="Buzz This" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.dzone.com/links/add.html?title=Output+Into+%E2%80%93+Audit+Trails&amp;url=http%3A%2F%2Fscratchbox.co.uk%2F2012%2F05%2Foutput-into-audit-trails%2F" target="_blank"><img class="lightsocial_img" src="http://scratchbox.co.uk/wp-content/plugins/light-social/dzone.png" alt="Vote on DZone" title="Vote on DZone" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.facebook.com/sharer.php?t=Output+Into+%E2%80%93+Audit+Trails&amp;u=http%3A%2F%2Fscratchbox.co.uk%2F2012%2F05%2Foutput-into-audit-trails%2F" target="_blank"><img class="lightsocial_img" src="http://scratchbox.co.uk/wp-content/plugins/light-social/facebook.png" alt="Share on Facebook" title="Share on Facebook" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://delicious.com/save?title=Output+Into+%E2%80%93+Audit+Trails&amp;url=http%3A%2F%2Fscratchbox.co.uk%2F2012%2F05%2Foutput-into-audit-trails%2F" target="_blank"><img class="lightsocial_img" src="http://scratchbox.co.uk/wp-content/plugins/light-social/delicious.png" alt="Bookmark this on Delicious" title="Bookmark this on Delicious" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.dotnetkicks.com/kick/?title=Output+Into+%E2%80%93+Audit+Trails&amp;url=http%3A%2F%2Fscratchbox.co.uk%2F2012%2F05%2Foutput-into-audit-trails%2F" target="_blank"><img class="lightsocial_img" src="http://scratchbox.co.uk/wp-content/plugins/light-social/dotnetkicks.png" alt="Kick It on DotNetKicks.com" title="Kick It on DotNetKicks.com" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://dotnetshoutout.com/Submit?title=Output+Into+%E2%80%93+Audit+Trails&amp;url=http%3A%2F%2Fscratchbox.co.uk%2F2012%2F05%2Foutput-into-audit-trails%2F" target="_blank"><img class="lightsocial_img" src="http://scratchbox.co.uk/wp-content/plugins/light-social/dotnetshoutout.png" alt="Shout it" title="Shout it" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.linkedin.com/shareArticle?mini=true&amp;url=http%3A%2F%2Fscratchbox.co.uk%2F2012%2F05%2Foutput-into-audit-trails%2F&amp;title=Output+Into+%E2%80%93+Audit+Trails&amp;summary=&amp;source=" target="_blank"><img class="lightsocial_img" src="http://scratchbox.co.uk/wp-content/plugins/light-social/linkedin.png" alt="Share on LinkedIn" title="Share on LinkedIn" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.technorati.com/faves?add=http%3A%2F%2Fscratchbox.co.uk%2F2012%2F05%2Foutput-into-audit-trails%2F" target="_blank"><img class="lightsocial_img" src="http://scratchbox.co.uk/wp-content/plugins/light-social/technorati.png" alt="Bookmark this on Technorati" title="Bookmark this on Technorati" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://twitter.com/home?status=Reading+http%3A%2F%2Fscratchbox.co.uk%2F2012%2F05%2Foutput-into-audit-trails%2F" target="_blank"><img class="lightsocial_img" src="http://scratchbox.co.uk/wp-content/plugins/light-social/twitter.png" alt="Post on Twitter" title="Post on Twitter" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.google.com/buzz/post?url=http%3A%2F%2Fscratchbox.co.uk%2F2012%2F05%2Foutput-into-audit-trails%2F" target="_blank"><img class="lightsocial_img" src="http://scratchbox.co.uk/wp-content/plugins/light-social/google_buzz.png" alt="Google Buzz (aka. Google Reader)" title="Google Buzz (aka. Google Reader)" /></a>&nbsp;&nbsp;</div>]]></content:encoded>
			<wfw:commentRss>http://scratchbox.co.uk/2012/05/output-into-audit-trails/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Moving Database Objects between Schemas the quick way</title>
		<link>http://scratchbox.co.uk/2012/05/moving-database-objects-between-schemas-the-quick-way/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=moving-database-objects-between-schemas-the-quick-way</link>
		<comments>http://scratchbox.co.uk/2012/05/moving-database-objects-between-schemas-the-quick-way/#comments</comments>
		<pubDate>Fri, 11 May 2012 15:43:07 +0000</pubDate>
		<dc:creator>Zach Stagers</dc:creator>
				<category><![CDATA[SQL]]></category>
		<category><![CDATA[Schemas]]></category>
		<category><![CDATA[Transfer]]></category>

		<guid isPermaLink="false">http://scratchbox.co.uk/?p=114</guid>
		<description><![CDATA[I’ve been doing a bit of database re-structuring lately, and I came across a nice and quick way to move database objects between schemas. Instead of dropping and recreating the object in the schema you require it to be in &#8230; <a href="http://scratchbox.co.uk/2012/05/moving-database-objects-between-schemas-the-quick-way/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>I’ve been doing a bit of database re-structuring lately, and I came across a nice and quick way to move database objects between schemas. Instead of dropping and recreating the object in the schema you require it to be in – simply execute the below:</p>

<div class="wp_syntax"><div class="code"><pre class="tsql" style="font-family:monospace;"><span style="color: #0000FF;">ALTER</span> <span style="color: #0000FF;">SCHEMA</span> MySchema TRANSFER dbo.<span style="color: #202020;">Sproc</span>;</pre></div></div>

<p>The above example will move the object “dbo.Sproc” into the “MySchema” schema.</p>
<p>Short and sweet.</p>
<div class="lightsocial_container"><a class="lightsocial_a" href="http://digg.com/submit?url=http%3A%2F%2Fscratchbox.co.uk%2F2012%2F05%2Fmoving-database-objects-between-schemas-the-quick-way%2F&amp;title=Moving+Database+Objects+between+Schemas+the+quick+way" target="_blank"><img class="lightsocial_img" src="http://scratchbox.co.uk/wp-content/plugins/light-social/digg.png" alt="Digg This" title="Digg This" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.reddit.com/submit?url=http%3A%2F%2Fscratchbox.co.uk%2F2012%2F05%2Fmoving-database-objects-between-schemas-the-quick-way%2F&amp;title=Moving+Database+Objects+between+Schemas+the+quick+way" target="_blank"><img class="lightsocial_img" src="http://scratchbox.co.uk/wp-content/plugins/light-social/reddit.png" alt="Reddit This" title="Reddit This" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.stumbleupon.com/submit?url=http%3A%2F%2Fscratchbox.co.uk%2F2012%2F05%2Fmoving-database-objects-between-schemas-the-quick-way%2F&amp;title=Moving+Database+Objects+between+Schemas+the+quick+way" target="_blank"><img class="lightsocial_img" src="http://scratchbox.co.uk/wp-content/plugins/light-social/stumbleupon.png" alt="Stumble Now!" title="Stumble Now!" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://buzz.yahoo.com/buzz?targetUrl=http%3A%2F%2Fscratchbox.co.uk%2F2012%2F05%2Fmoving-database-objects-between-schemas-the-quick-way%2F&amp;headline=Moving+Database+Objects+between+Schemas+the+quick+way" target="_blank"><img class="lightsocial_img" src="http://scratchbox.co.uk/wp-content/plugins/light-social/yahoo_buzz.png" alt="Buzz This" title="Buzz This" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.dzone.com/links/add.html?title=Moving+Database+Objects+between+Schemas+the+quick+way&amp;url=http%3A%2F%2Fscratchbox.co.uk%2F2012%2F05%2Fmoving-database-objects-between-schemas-the-quick-way%2F" target="_blank"><img class="lightsocial_img" src="http://scratchbox.co.uk/wp-content/plugins/light-social/dzone.png" alt="Vote on DZone" title="Vote on DZone" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.facebook.com/sharer.php?t=Moving+Database+Objects+between+Schemas+the+quick+way&amp;u=http%3A%2F%2Fscratchbox.co.uk%2F2012%2F05%2Fmoving-database-objects-between-schemas-the-quick-way%2F" target="_blank"><img class="lightsocial_img" src="http://scratchbox.co.uk/wp-content/plugins/light-social/facebook.png" alt="Share on Facebook" title="Share on Facebook" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://delicious.com/save?title=Moving+Database+Objects+between+Schemas+the+quick+way&amp;url=http%3A%2F%2Fscratchbox.co.uk%2F2012%2F05%2Fmoving-database-objects-between-schemas-the-quick-way%2F" target="_blank"><img class="lightsocial_img" src="http://scratchbox.co.uk/wp-content/plugins/light-social/delicious.png" alt="Bookmark this on Delicious" title="Bookmark this on Delicious" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.dotnetkicks.com/kick/?title=Moving+Database+Objects+between+Schemas+the+quick+way&amp;url=http%3A%2F%2Fscratchbox.co.uk%2F2012%2F05%2Fmoving-database-objects-between-schemas-the-quick-way%2F" target="_blank"><img class="lightsocial_img" src="http://scratchbox.co.uk/wp-content/plugins/light-social/dotnetkicks.png" alt="Kick It on DotNetKicks.com" title="Kick It on DotNetKicks.com" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://dotnetshoutout.com/Submit?title=Moving+Database+Objects+between+Schemas+the+quick+way&amp;url=http%3A%2F%2Fscratchbox.co.uk%2F2012%2F05%2Fmoving-database-objects-between-schemas-the-quick-way%2F" target="_blank"><img class="lightsocial_img" src="http://scratchbox.co.uk/wp-content/plugins/light-social/dotnetshoutout.png" alt="Shout it" title="Shout it" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.linkedin.com/shareArticle?mini=true&amp;url=http%3A%2F%2Fscratchbox.co.uk%2F2012%2F05%2Fmoving-database-objects-between-schemas-the-quick-way%2F&amp;title=Moving+Database+Objects+between+Schemas+the+quick+way&amp;summary=&amp;source=" target="_blank"><img class="lightsocial_img" src="http://scratchbox.co.uk/wp-content/plugins/light-social/linkedin.png" alt="Share on LinkedIn" title="Share on LinkedIn" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.technorati.com/faves?add=http%3A%2F%2Fscratchbox.co.uk%2F2012%2F05%2Fmoving-database-objects-between-schemas-the-quick-way%2F" target="_blank"><img class="lightsocial_img" src="http://scratchbox.co.uk/wp-content/plugins/light-social/technorati.png" alt="Bookmark this on Technorati" title="Bookmark this on Technorati" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://twitter.com/home?status=Reading+http%3A%2F%2Fscratchbox.co.uk%2F2012%2F05%2Fmoving-database-objects-between-schemas-the-quick-way%2F" target="_blank"><img class="lightsocial_img" src="http://scratchbox.co.uk/wp-content/plugins/light-social/twitter.png" alt="Post on Twitter" title="Post on Twitter" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.google.com/buzz/post?url=http%3A%2F%2Fscratchbox.co.uk%2F2012%2F05%2Fmoving-database-objects-between-schemas-the-quick-way%2F" target="_blank"><img class="lightsocial_img" src="http://scratchbox.co.uk/wp-content/plugins/light-social/google_buzz.png" alt="Google Buzz (aka. Google Reader)" title="Google Buzz (aka. Google Reader)" /></a>&nbsp;&nbsp;</div>]]></content:encoded>
			<wfw:commentRss>http://scratchbox.co.uk/2012/05/moving-database-objects-between-schemas-the-quick-way/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

