<?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>Steve Stedman</title>
	<atom:link href="http://stevestedman.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://stevestedman.com</link>
	<description>SQL Server Stuff</description>
	<lastBuildDate>Mon, 13 Feb 2012 05:46:58 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>KeePass &#8211; for security and time savings</title>
		<link>http://stevestedman.com/2012/02/keepass-for-security-and-time-savings/</link>
		<comments>http://stevestedman.com/2012/02/keepass-for-security-and-time-savings/#comments</comments>
		<pubDate>Sun, 12 Feb 2012 21:10:25 +0000</pubDate>
		<dc:creator>SteveStedman</dc:creator>
				<category><![CDATA[LEAN]]></category>
		<category><![CDATA[Lean Office]]></category>
		<category><![CDATA[Steve]]></category>
		<category><![CDATA[Video]]></category>

		<guid isPermaLink="false">http://stevestedman.com/?p=1181</guid>
		<description><![CDATA[After a recent tour at a couple companies who are using the LEAN process, I have decided to take on LEAN in my everyday work. This is the first in what I think will be many videos on the Lean Office topic. Click the link below to watch the video. Lean2SecondKeePass &#160; For more info [...]]]></description>
			<content:encoded><![CDATA[<p>After a recent tour at a couple companies who are using the <strong>LEAN</strong> process, I have decided to take on <strong>LEAN</strong> in my everyday work.</p>
<p>This is the first in what I think will be many videos on the Lean Office topic.</p>
<p>Click the link below to watch the video.</p>
<p><a href="http://stevestedman.com/wp-content/uploads/2012/02/Lean2SecondKeePass.mp4">Lean2SecondKeePass</a></p>
<div id="flashcontent3675"><video controls='controls' preload='metadata' width='640' height='360'>
<source src='http://stevestedman.com/wp-content/uploads/2012/02/Lean2SecondKeePass.mp4' type='video/mp4'>
</video>
</div>

<script type="text/javascript">
	swfobject.embedSWF('http://stevestedman.com/wp-content/plugins/video-embed-thumbnail-generator/flash/StrobeMediaPlayback.swf', 'flashcontent3675', '640', '360', '10.1.0', 'http://stevestedman.com/wp-content/plugins/video-embed-thumbnail-generator/flash/expressInstall.swf', {src:'http%3A%2F%2Fstevestedman.com%2Fwp-content%2Fuploads%2F2012%2F02%2FLean2SecondKeePass.mp4', controlBarMode:'docked', controlBarAutoHide:'true', playButtonOverlay:'true', loop:'false', autoPlay:'false', streamType:'liveOrRecorded', scaleMode:'letterbox', skin:'http%3A%2F%2Fstevestedman.com%2Fwp-content%2Fplugins%2Fvideo-embed-thumbnail-generator%2Fflash%2Fskin%2Fkg_skin.xml'}, {allowfullscreen:'true', allowscriptaccess:'always', base:'http://stevestedman.com/wp-content/plugins/video-embed-thumbnail-generator/flash/'})
</script>

<p>&nbsp;</p>
<p><a title="KeePass – to improve your process" href="http://stevestedman.com/2012/02/keepass-to-improve-your-process/">For more info on KeePass see the detailed article with instructions on using KeePass</a>.</p>
<p>&nbsp;</p>
<p>Follow hash tag #leanOffice on Twitter</p>
]]></content:encoded>
			<wfw:commentRss>http://stevestedman.com/2012/02/keepass-for-security-and-time-savings/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
<enclosure url="http://stevestedman.com/wp-content/uploads/2012/02/Lean2SecondKeePass.mp4" length="8517026" type="video/mp4" />
		</item>
		<item>
		<title>KeePass &#8211; to improve your process</title>
		<link>http://stevestedman.com/2012/02/keepass-to-improve-your-process/</link>
		<comments>http://stevestedman.com/2012/02/keepass-to-improve-your-process/#comments</comments>
		<pubDate>Sun, 12 Feb 2012 19:21:29 +0000</pubDate>
		<dc:creator>SteveStedman</dc:creator>
				<category><![CDATA[LEAN]]></category>
		<category><![CDATA[Steve]]></category>
		<category><![CDATA[YES]]></category>

		<guid isPermaLink="false">http://stevestedman.com/?p=1192</guid>
		<description><![CDATA[Before proceeding with the article, please take this quick password safety test. Password Safety Test – Score one point for every YES answer.: Do you write your passwords down?  ( YES  /  NO ) Do you ever re-use a password on multiple systems or websites?  ( YES  /  NO ) Are your passwords shorter than [...]]]></description>
			<content:encoded><![CDATA[<p>Before proceeding with the article, please take this quick password safety test.</p>
<p><strong>Password Safety Test – Score one point for every YES answer.:</strong></p>
<ol start="1">
<li>Do you write your passwords down?  ( <strong>YES</strong>  /  NO )</li>
<li>Do you ever re-use a password on multiple systems or websites?  ( <strong>YES</strong>  /  NO )</li>
<li>Are your passwords shorter than 8 characters?  ( <strong>YES</strong>  /  NO )</li>
<li>Do you use dictionary words as your password or part of your password? ( <strong>YES</strong>  /  NO )</li>
<li>Do you ever use family or pet names as your password?  ( <strong>YES</strong>  /  NO )</li>
<li>If you lift up your keyboard right now, will you find one or more passwords? (<strong>YES</strong>  /  NO )</li>
</ol>
<p>Scoring:</p>
<p>If you answered the above questions with <strong>YES</strong> more than 5 times, then your use of passwords are extremely insecure and you may be in danger, you may be in serious trouble, keep reading and find out what you can do to fix this.</p>
<p>If you answered <strong>YES</strong> more than 3 times then you passwords are insecure and could lead to trouble for you, keep reading and find out what you can do to fix this.</p>
<p>If you answered <strong>YES</strong> at least once, then keep reading.  You are not doing bad, but you could use some help.</p>
<p>&nbsp;</p>
<p>KeePass is a free open-source password manager and safe which helps you keep track of all of your passwords.  KeePass will help you be more secure in your use of passwords.</p>
<p><strong>Too Many Passwords:</strong></p>
<p>Prior to using KeePass I would need to remember dozens of passwords for all of the different websites and systems that I regularly use, along with the password for the systems that you rarely use.  These passwords usually ended up on sticky notes on the side of my monitor or under my keyboard.</p>
<p><strong>Re-using passwords:</strong></p>
<p>It is very common for someone to use the same password again and again at every website they signup at.  This alone is a security risk, for instance if you sign up with PayPal with one username and password combination, then you sign up some online store to buy something.  If you were to use the same password, then the company with the online store would know your PayPal password.  Even worse than that, if one website with your password on it was hacked, and the password list was stolen, then those hackers would have access to a password that matched your PayPal account.</p>
<p><strong>Forgetting your passwords:</strong></p>
<p>Have you ever gone on vacation for a couple weeks, then when returning home or to work, you realized that you had forgotten one of your commonly used passwords.  Have you ever attempted to configure you email account on a new computer and realized that you entered your email account when you set up your old computer, and haven’t typed it since, and have no idea what that password is.  KeePass can help with this.</p>
<p>KeePass is a tool that I have been using for a while now.  When I first started using it, I wasn’t too sure if it would work for me, but it turned out great.  This article outlines the cool things that I have discovered while using KeePass.  This is not a paid advertisement of any kind, just my opinion and nothing more.</p>
<p>The main KeePass page is shown below.  You can build a hierarchy of passwords and organize them into groups or folders.  You can also search on a term if you forget which group your password is in.</p>
<p><a href="http://stevestedman.com/wp-content/uploads/2012/02/KeePass_Main_Screen.jpg"><img class="aligncenter size-full wp-image-1193" title="KeePass_Main_Screen" src="http://stevestedman.com/wp-content/uploads/2012/02/KeePass_Main_Screen.jpg" alt="" width="587" height="450" /></a></p>
<p>&nbsp;</p>
<p>All it takes to get started is to pick the category that you want to add a password to, then click to add an entry.  The screen below will be shown.  Passwords are generally hidden with ******* since you don’t have a reason to see the password, you just need to copy it to the clipboard and paste it into a page.</p>
<p><a href="http://stevestedman.com/wp-content/uploads/2012/02/KeePass_Edit_Entry.jpg"><img class="aligncenter size-full wp-image-1194" title="KeePass_Edit_Entry" src="http://stevestedman.com/wp-content/uploads/2012/02/KeePass_Edit_Entry.jpg" alt="" width="479" height="535" /></a></p>
<p>&nbsp;</p>
<p>Another common problem that is fixed by KeePass, is the generation of strong passwords.  Strong passwords are passwords that would not be easily guessed by someone trying to break into your account.  The challenge is creating strong passwords that you can easily remember.  KeePass eliminates the need to remember any passwords, beyond the one password required to get into your KeePass system.</p>
<p>Rules of thumb when choosing passwords:</p>
<ul>
<li>Avoid using dictionary words.</li>
<li>Never use your account name as its password.</li>
<li>Use different passwords for each machine.</li>
<li>Don&#8217;t use common misspellings of dictionary words (including replacing &#8220;i&#8221; with &#8220;1&#8243;).</li>
<li>Don’t use your first or last name in any form.</li>
<li>Don’t use your spouse&#8217;s or child&#8217;s name.</li>
<li>Don’t use your pet’s name.</li>
<li>Don’t use a password shorter than 8 characters.</li>
<li>Don’t use any “method” for creating passwords.</li>
</ul>
<p>There are many other rules around choosing passwords, but to keep it simple the longer and more random the password, the more secure it will be.</p>
<p>The chart below shows the cracking time based on the length of the password.</p>
<p><a href="http://stevestedman.com/wp-content/uploads/2012/02/Cracking_time.png"><img class="aligncenter size-full wp-image-1195" title="Cracking_time" src="http://stevestedman.com/wp-content/uploads/2012/02/Cracking_time.png" alt="" width="604" height="304" /></a></p>
<p>&nbsp;</p>
<p><a href="http://stevestedman.com/wp-content/uploads/2012/02/KeePass_Password_Generator.jpg"><img class="aligncenter size-full wp-image-1196" title="KeePass_Password_Generator" src="http://stevestedman.com/wp-content/uploads/2012/02/KeePass_Password_Generator.jpg" alt="" width="480" height="527" /></a></p>
<p>KeePass provides tools for generating passwords for you, completely at random, using your keyboard and mouse for random input on the password.</p>
<p><a href="http://stevestedman.com/wp-content/uploads/2012/02/KeePass_Get_Random.jpg"><img class="aligncenter size-full wp-image-1197" title="KeePass_Get_Random" src="http://stevestedman.com/wp-content/uploads/2012/02/KeePass_Get_Random.jpg" alt="" width="609" height="431" /></a></p>
<p>Here are some examples of passwords generated by KeePass:</p>
<p>XUkaojtVwlMxHAZi</p>
<p>9YIlMRz1edPcieagLLpFipnJs8VJ4JUoyGk6Ay01</p>
<p>8A3FpRnkyv08oMS3CVhj6qRX3YFffRcST6ZpCYbw</p>
<p>After looking at these passwords you might think “How can I ever remember a password like that”.  The simple answer is that you won’t, but you don’t need to.   Just have KeePass store the password for you, then when you need it, copy it to the clipboard and paste it into the password field.</p>
<p><strong>AutoType:</strong></p>
<p>KeePass has a nice feature called autotype.  With this you can define the sequence that you passwords should be entered with usernames.  For instance an AutoType sequence of {USERNAME}{TAB}{PASSWORD}{ENTER} would send your username, hit tab to go to the next field, then enter your password and hit enter to submit the form.  This is very useful for forms that require multiple lines of input to log in.</p>
<p>&nbsp;</p>
<p>With KeePass you set the master password for the whole password safe.  Once this has been set, you need to enter this password every time that you start KeePass.  If KeePass is minimized to an icon, you need to enter this password to restore it.</p>
<p>&nbsp;</p>
<p><strong>So what passwords do I need to remember?</strong></p>
<p>You will only need to remember one password, the password used to use the KeePass program.  You can choose this password, keep in mind that you will be typing this password often as you use the system.</p>
<p><a href="http://stevestedman.com/wp-content/uploads/2012/02/KeePass_Set_Master_key.jpg"><img class="aligncenter size-full wp-image-1198" title="KeePass_Set_Master_key" src="http://stevestedman.com/wp-content/uploads/2012/02/KeePass_Set_Master_key.jpg" alt="" width="534" height="310" /></a></p>
<p>&nbsp;</p>
<p><a title="KeePass – for security and time savings" href="http://stevestedman.com/2012/02/keepass-for-security-and-time-savings/">Click here to see a video on KeePass and how it applies to LEAN Process</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://stevestedman.com/2012/02/keepass-to-improve-your-process/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Calculating Factorials with a Recursive CTE</title>
		<link>http://stevestedman.com/2012/02/calculating-factorials-with-a-recursive-cte/</link>
		<comments>http://stevestedman.com/2012/02/calculating-factorials-with-a-recursive-cte/#comments</comments>
		<pubDate>Sat, 11 Feb 2012 17:17:06 +0000</pubDate>
		<dc:creator>SteveStedman</dc:creator>
				<category><![CDATA[CTE]]></category>

		<guid isPermaLink="false">http://stevestedman.com/?p=1166</guid>
		<description><![CDATA[What is a Factorial: The product of an integer and all the integers below it; e.g., factorial four (4!) is equal to 24. &#160; The factorial of a positive integer n, written n!, is the product of all the positive integers from 1 up to and including n Example: 1! = 1 2! = 1 * 2 [...]]]></description>
			<content:encoded><![CDATA[<h3>What is a Factorial:</h3>
<p>The product of an integer and all the integers below it; e.g., factorial four (4!) is equal to 24.</p>
<p>&nbsp;</p>
<p>The factorial of a positive integer n, written n!, is the product of all the positive integers from 1 up to and including n<br />
Example:<br />
<strong>1! = 1</strong><br />
<strong>2! = 1 * 2 = 2</strong><br />
<strong>3! = 1 * 2 * 3 = 6</strong><br />
<strong>4! = 1 * 2 * 3 * 4 = 24</strong></p>
<p>&nbsp;</p>
<p>It is simple to do with a recursive function, and actually commonly used as a programming interview question to determine if you understand recursion.  For instance, years ago, I was asked the following during an interview at Microsoft.</p>
<blockquote><p><strong>What is recursion? Calculate factorial numbers using a recursive function?</strong></p></blockquote>
<p>Which is very easy to answer using C, which was the programming language of choice when I was asked it.  But what if you were asked that on an intervie for a SQL Server DBA, or SQL Server Programmer job.  Your first answer might be to use a recursive stored procedure, which would be a good answer, but what if you were asked the following, how would you answer it?</p>
<blockquote><p><strong>What is recursion?  Using TSQL write a query to calculate factorials without creating any stored procedures or functions.</strong></p></blockquote>
<p>Think, think, think&#8230;. You want the job, and that is the question that the interviewer is asking you.  How do you solve it?</p>
<ol>
<li>First, make sure you understand factorials.  If you don&#8217;t understand what a factorial is you won&#8217;t get anywhere with this.</li>
<li>Then write the query, using a Recursive <a title="Recursive CTE’s" href="http://stevestedman.com/2011/11/recursive-ctes/">Common Table Expression</a>.</li>
</ol>
<p>Here is how I solved it.</p>
<p>First, get started with a simple <a title="Common Table Expressions (CTE)" href="http://stevestedman.com/consulting/virtual-classes/common-table-expressions-cte/"><strong>CTE</strong> </a>that just calculates the first factorial 1! as shown below.  Pretty simple at this point.  The result set is correct, the Factorial of 1 is just 1.</p>
<p><a href="http://stevestedman.com/wp-content/uploads/2012/02/CTE_Factorial1.png"><img class="aligncenter size-full wp-image-1167" title="CTE_Factorial1" src="http://stevestedman.com/wp-content/uploads/2012/02/CTE_Factorial1.png" alt="" width="377" height="478" /></a></p>
<p>&nbsp;</p>
<p>Next, I would add the <a title="Recursive CTE’s" href="http://stevestedman.com/2011/11/recursive-ctes/">recursive <strong>CTE</strong></a> query to continue with the factorial calculations beyond 1!, this time going up to 5!  When working with <a title="Recursive CTE’s" href="http://stevestedman.com/2011/11/recursive-ctes/">recursive <strong>CTE</strong></a>&#8216;s you usually want to have an escape clause to avoid too much recursion.  In this example the <strong>CTE</strong> exits at 5.</p>
<p><a href="http://stevestedman.com/wp-content/uploads/2012/02/CTE_Factorial2.png"><img class="aligncenter size-full wp-image-1168" title="CTE_Factorial2" src="http://stevestedman.com/wp-content/uploads/2012/02/CTE_Factorial2.png" alt="" width="470" height="510" /></a></p>
<p>&nbsp;</p>
<p>That&#8217;s nice, but lets go further.  Lets go for 20!  Which you will see in the image below caused some problems as shown with an error of &#8220;Arithmetic overflow error converting expression to data type int.&#8221;</p>
<p><a href="http://stevestedman.com/wp-content/uploads/2012/02/CTE_Factorial3.png"><img class="aligncenter size-full wp-image-1170" title="CTE_Factorial3" src="http://stevestedman.com/wp-content/uploads/2012/02/CTE_Factorial3.png" alt="" width="533" height="478" /></a></p>
<p>&nbsp;</p>
<p>Now to fix the overflow.  It turns out that Factorial of 20 gets big pretty quick, and an integer only can hold a number up to just over 2 Billion. But a BIGINT can go much further, to just over 9 Quintillion (US).  So to fix this we cast the factorial column to be a BIGINT rather than an INT.</p>
<h3>INT</h3>
<p>Range: -2^31 (-2,147,483,648) to 2^31-1 (2,147,483,647)<br />
Space: 4 Bytes</p>
<h3>BIGINT</h3>
<p>Range: -2^63 (-9,223,372,036,854,775,808) to 2^63-1 (9,223,372,036,854,775,807)<br />
Space: 8 Bytes</p>
<p>&nbsp;</p>
<p>So here we go with an attempt to get to 20! , which works great.</p>
<p><a href="http://stevestedman.com/wp-content/uploads/2012/02/CTE_Factorial4.png"><img class="aligncenter size-full wp-image-1172" title="CTE_Factorial4" src="http://stevestedman.com/wp-content/uploads/2012/02/CTE_Factorial4.png" alt="" width="593" height="758" /></a></p>
<p>But how far can we go with the BIGINT 9 Quintillion limit of BIGINT.  As it turns out 21! exceeds the size of a BIGINT.</p>
<p><a href="http://stevestedman.com/wp-content/uploads/2012/02/CTE_Factorial5.png"><img class="aligncenter size-full wp-image-1173" title="CTE_Factorial5" src="http://stevestedman.com/wp-content/uploads/2012/02/CTE_Factorial5.png" alt="" width="571" height="318" /></a></p>
<p>&nbsp;</p>
<p>So what now?   What if we want to calculate more than 20! using SQL Server?     Cast it to a NUMERIC(38,0) which gives us 38 digits to work with as shown here.</p>
<p><a href="http://stevestedman.com/wp-content/uploads/2012/02/CTE_Factorial6.png"><img class="aligncenter size-full wp-image-1174" title="CTE_Factorial6" src="http://stevestedman.com/wp-content/uploads/2012/02/CTE_Factorial6.png" alt="" width="688" height="918" /></a></p>
<p>&nbsp;</p>
<p>Now what???</p>
<p>I haven&#8217;t been able to find a solution to do math and store the results larger than a NUMERIC(38,0).</p>
<p>Here is the final query.</p>
<blockquote><p><span style="color: blue;">WITH</span> <span style="color: maroon;">factorial</span> <span style="color: maroon;">(</span><span style="color: maroon;">n</span><span style="color: silver;">,</span> <span style="color: maroon;">factorial</span><span style="color: maroon;">)</span><br />
<span style="color: blue;">AS</span> <span style="color: maroon;">(</span><span style="color: blue;">SELECT</span> <span style="color: black;">1</span><span style="color: silver;">,</span><br />
<span style="color: fuchsia;"><em>CAST</em></span><span style="color: maroon;">(</span><span style="color: black;">1</span> <span style="color: blue;">AS</span> <span style="color: black;"><em>NUMERIC</em></span><span style="color: maroon;">(</span><span style="color: black;">38</span><span style="color: silver;">,</span> <span style="color: black;">0</span><span style="color: maroon;">)</span><span style="color: maroon;">)</span> <span style="color: green;"><em>&#8211; Cast to BIGINT to avoid overflow</em></span><br />
<span style="color: blue;">UNION</span> <span style="color: blue;">ALL</span> <span style="color: green;"><em>&#8211; here is where it gets recursive</em></span><br />
<span style="color: blue;">SELECT</span> <span style="color: maroon;">n</span> <span style="color: silver;">+</span> <span style="color: black;">1</span><span style="color: silver;">,</span><br />
<span style="color: maroon;">(</span> <span style="color: maroon;">n</span> <span style="color: silver;">+</span> <span style="color: black;">1</span> <span style="color: maroon;">)</span> <span style="color: silver;">*</span> <span style="color: maroon;">factorial</span><br />
<span style="color: blue;">FROM</span>   <span style="color: maroon;">factorial</span> <span style="color: green;"><em>&#8211; reference back to the CTE</em></span><br />
<span style="color: blue;">WHERE</span>  <span style="color: maroon;">n</span> <span style="color: silver;">&lt;</span> <span style="color: black;">33</span> <span style="color: green;"><em>&#8211; abort when we get to 33!</em></span><br />
<span style="color: maroon;">)</span><br />
<span style="color: blue;">SELECT</span> <span style="color: maroon;">n</span><span style="color: silver;">,</span><br />
<span style="color: maroon;">factorial</span><br />
<span style="color: blue;">FROM</span>   <span style="color: maroon;">factorial</span><span style="color: silver;">;</span></p></blockquote>
<p>&nbsp;</p>
<p>I hope you have found this useful.</p>
<p>&nbsp;</p>
]]></content:encoded>
			<wfw:commentRss>http://stevestedman.com/2012/02/calculating-factorials-with-a-recursive-cte/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>CTE &#8211; With An Insert Statement</title>
		<link>http://stevestedman.com/2012/02/cte-with-an-insert-statement/</link>
		<comments>http://stevestedman.com/2012/02/cte-with-an-insert-statement/#comments</comments>
		<pubDate>Sat, 11 Feb 2012 15:52:46 +0000</pubDate>
		<dc:creator>SteveStedman</dc:creator>
				<category><![CDATA[CTE]]></category>
		<category><![CDATA[SQL Saturday]]></category>
		<category><![CDATA[INSERT]]></category>
		<category><![CDATA[INT]]></category>
		<category><![CDATA[SELECT]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[UPDATE]]></category>

		<guid isPermaLink="false">http://stevestedman.com/?p=1153</guid>
		<description><![CDATA[Queries with Common table expressions (CTE) are made up of two parts, the CTE part, and the SQL that references the CTE.  In preparation for SQL Saturday, the question came up of can you use an INSERT or UPDATE statement with a CTE.  Referring to the documentation I confirmed that using an insert or update [...]]]></description>
			<content:encoded><![CDATA[<p>Queries with Common table expressions (<strong>CTE</strong>) are made up of two parts, the <strong>CTE</strong> part, and the <strong>SQL</strong> that references the <strong>CTE</strong>.  In preparation for <a title="SQL Saturday 108 in Redmond WA" href="http://stevestedman.com/speaking/sql-saturday-108-in-redmond-wa/">SQL Saturday</a>, the question came up of can you use an <strong>INSERT</strong> or <strong>UPDATE</strong> statement with a <strong>CTE</strong>.  Referring to the documentation I confirmed that using an insert or update inside of the <strong>CTE</strong> is invalid, but you can use an insert or update statement outside of the <strong>CTE</strong>.</p>
<p>&nbsp;</p>
<p>For Example.</p>
<blockquote><p><code><span style="font-family: 'Courier New'; font-size: x-small;"><br />
<span style="color: blue;">DECLARE</span> <span style="color: #8000ff;">@NumTableVar</span> <span style="color: blue;">TABLE</span><span style="color: maroon;">(</span> <span style="color: maroon;">n</span> <span style="color: black;"><em>INT</em></span><span style="color: maroon;">)</span><span style="color: silver;">;</span></span></code></p>
<p>&nbsp;</p>
<p><span style="color: blue;">;WITH</span> <span style="color: maroon;">numbers</span> <span style="color: maroon;">(</span><span style="color: maroon;">n</span><span style="color: maroon;">)</span><br />
<span style="color: blue;">AS</span> <span style="color: maroon;">(</span><span style="color: blue;">SELECT</span> <span style="color: black;">1</span><br />
<span style="color: blue;">UNION</span> <span style="color: blue;">ALL</span><br />
<span style="color: blue;">SELECT</span> <span style="color: black;">1</span> <span style="color: silver;">+</span> <span style="color: maroon;">n</span><br />
<span style="color: blue;">FROM</span>   <span style="color: maroon;">numbers</span><br />
<span style="color: blue;">WHERE</span>  <span style="color: maroon;">n</span> <span style="color: silver;">&lt;</span> <span style="color: black;">1000</span><span style="color: maroon;">)</span></p>
<p><span style="color: blue;">INSERT</span> <span style="color: blue;">INTO</span> <span style="color: #8000ff;">@NumTableVar</span>   <span style="color: maroon;">(</span><span style="color: maroon;">n</span><span style="color: maroon;">)</span><br />
<span style="color: blue;">SELECT</span> <span style="color: maroon;">n</span><br />
<span style="color: blue;">FROM</span>   <span style="color: maroon;">numbers</span><br />
<span style="color: blue;">OPTION</span> <span style="color: maroon;">(</span><span style="color: blue;">MAXRECURSION</span> <span style="color: black;">0</span><span style="color: maroon;">)</span><span style="color: silver;">;</span></p>
<p><code><span style="font-family: 'Courier New'; font-size: x-small;"><br />
<span style="color: blue;">SELECT</span> <span style="color: silver;">*</span><br />
<span style="color: blue;">FROM</span>   <span style="color: #8000ff;">@NumTableVar</span><span style="color: silver;">;</span><br />
</span><br />
</code></p></blockquote>
<p>When run confirms that you can use the insert statement with a <strong>CTE</strong>, but not inside of a <strong>CTE</strong>.</p>
<p>&nbsp;</p>
<p>This would be very useful if you had just created a table and wanted to fill it up quickly for testing purposes.</p>
]]></content:encoded>
			<wfw:commentRss>http://stevestedman.com/2012/02/cte-with-an-insert-statement/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Fibonacci Sequence</title>
		<link>http://stevestedman.com/2012/02/fibonacci-sequence/</link>
		<comments>http://stevestedman.com/2012/02/fibonacci-sequence/#comments</comments>
		<pubDate>Sat, 11 Feb 2012 03:03:29 +0000</pubDate>
		<dc:creator>SteveStedman</dc:creator>
				<category><![CDATA[CTE]]></category>
		<category><![CDATA[SQL Saturday]]></category>
		<category><![CDATA[Fibonacci Sequence]]></category>

		<guid isPermaLink="false">http://stevestedman.com/?p=1142</guid>
		<description><![CDATA[As part of my CTE research for my SQL Saturday presentation in Redmond in 2 weeks I decided to take on some classic computer science algorithms with CTE&#8217;s. Here is what I cam up with. Any math geek can tell you what the Fibonacci Sequence is, but do you know how to calculate it with [...]]]></description>
			<content:encoded><![CDATA[<p>As part of my CTE research for my<a title="SQL Saturday 108 in Redmond WA" href="http://stevestedman.com/speaking/sql-saturday-108-in-redmond-wa/"> SQL Saturday presentation in Redmond </a>in 2 weeks I decided to take on some classic computer science algorithms with CTE&#8217;s. Here is what I cam up with.</p>
<p>Any math geek can tell you what the <strong>Fibonacci Sequence</strong> is, but do you know how to calculate it with a query?</p>
<h3>First, what is the Fibonacci Sequence?</h3>
<div>
<p>By definition, the first two numbers in the Fibonacci sequence are 0 and 1, and each subsequent number is the sum of the previous two.</p>
</div>
<div></div>
<div>For instance, the following are Fibonacci Numbers:</div>
<div><strong>0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610, 987, 1597, 2584, 4181, 6765, 10946, 17711, 28657, 46368, 75025, 121393, 196418, 317811, 514229, 832040, 1346269, 2178309, 3524578, 5702887, 9227465, 14930352, 24157817, 39088169, 63245986, 102334155, 165580141, 267914296, 433494437, 701408733 &#8230;</strong></div>
<div></div>
<p>&nbsp;</p>
<div></div>
<h3>Fibonacci Sequence as a Computer Science Challenge</h3>
<p>Often times calculating the <strong>Fibonacci Sequence</strong> is used as a computer science puzzle, or programming interview question to see if you understand recursion.  It is very simple to do in any programming language that supports recursion.</p>
<p>&nbsp;</p>
<p>So what is recursion&#8230;  Recursion is a method of programming where a function ends up calling back into itself.</p>
<div></div>
<h3>Writing a query to calculate the Fibonacci Sequence</h3>
<p>In order to do this you need to understand recursion and <a title="Recursive CTE’s" href="http://stevestedman.com/2011/11/recursive-ctes/">CTE</a>&#8216;s.</p>
<p>The following query uses a recursive CTE query to generate the fibonacci sequence.</p>
<blockquote>
<div><span style="font-family: Courier New; font-size: 10pt;"><span style="font-family: Courier New; font-size: 10pt;"><br />
<span style="color: green;"><em>&#8211; Calculating the Fibonacci sequence </em></span></span></span><span style="color: blue;">WITH</span> <span style="color: maroon;">Fibonacci</span> <span style="color: maroon;">(</span><span style="color: maroon;">PrevN</span><span style="color: silver;">,</span> <span style="color: maroon;">N</span><span style="color: maroon;">)</span> <span style="color: blue;">AS</span></p>
<p><span style="color: maroon;">(</span> <span style="color: blue;">SELECT</span> <span style="color: black;">0</span><span style="color: silver;">,</span> <span style="color: black;">1</span></p>
<p><span style="color: blue;">UNION</span> <span style="color: blue;">ALL</span></p>
<p><span style="color: blue;">SELECT</span> <span style="color: maroon;">N</span><span style="color: silver;">,</span> <span style="color: maroon;">PrevN</span> <span style="color: silver;">+</span> <span style="color: maroon;">N</span></p>
<p><span style="color: blue;">FROM</span> <span style="color: maroon;">Fibonacci</span></p>
<p><span style="color: blue;">WHERE</span> <span style="color: maroon;">N</span> <span style="color: silver;">&lt;</span> <span style="color: black;">1000000000</span></p>
<p><span style="color: maroon;">)</span></p>
<p><span style="color: blue;">SELECT</span> <span style="color: maroon;">PrevN</span> <span style="color: blue;">as</span> <span style="color: maroon;">Fibo</span></p>
<p><span style="color: blue;">FROM</span> <span style="color: maroon;">Fibonacci</span></p>
<p><span style="color: blue;">OPTION</span> <span style="color: maroon;">(</span><span style="color: blue;">MAXRECURSION</span> <span style="color: black;">0</span><span style="color: maroon;">)</span><span style="color: silver;">;</span></p>
</div>
</blockquote>
<p>&nbsp;</p>
<p>Which generates the following output.</p>
<p style="text-align: center;"><a href="http://stevestedman.com/wp-content/uploads/2012/02/CTE_Fibonacci.png"><img class="size-full wp-image-1145 aligncenter" title="CTE_Fibonacci" src="http://stevestedman.com/wp-content/uploads/2012/02/CTE_Fibonacci.png" alt="" width="175" height="914" /></a></p>
<p style="text-align: left;">Now to make it more fun, using the <a title="Converting part of a result set to a comma separated list" href="http://stevestedman.com/2011/10/converting-part-of-a-result-set-to-a-comma-separated-list/">CSV conversion from a previous blog post, how do we convert it to a Comma Separated List</a>.</p>
<blockquote>
<div><span style="font-family: Courier New; font-size: 10pt;"><span style="font-family: Courier New; font-size: 10pt;"><br />
<span style="color: blue;">WITH</span> <span style="color: maroon;">Fibonacci</span> <span style="color: maroon;">(</span><span style="color: maroon;">PrevN</span><span style="color: silver;">,</span> <span style="color: maroon;">N</span><span style="color: maroon;">)</span> <span style="color: blue;">AS</span></span></span><span style="color: maroon;">(</span> <span style="color: blue;">SELECT</span> <span style="color: black;">0</span><span style="color: silver;">,</span> <span style="color: black;">1</span></p>
<p><span style="color: blue;">UNION</span> <span style="color: blue;">ALL</span></p>
<p><span style="color: blue;">SELECT</span> <span style="color: maroon;">N</span><span style="color: silver;">,</span> <span style="color: maroon;">PrevN</span> <span style="color: silver;">+</span> <span style="color: maroon;">N</span></p>
<p><span style="color: blue;">FROM</span> <span style="color: maroon;">Fibonacci</span></p>
<p><span style="color: blue;">WHERE</span> <span style="color: maroon;">N</span> <span style="color: silver;">&lt;</span> <span style="color: black;">1000000000</span></p>
<p><span style="color: maroon;">)</span></p>
<p><span style="color: blue;">SELECT</span> <span style="color: fuchsia;"><em>Substring</em></span><span style="color: maroon;">(</span><span style="color: maroon;">(</span><span style="color: blue;">SELECT</span> <span style="color: fuchsia;"><em>cast</em></span><span style="color: maroon;">(</span><span style="color: red;">&#8216;, &#8217;</span> <span style="color: blue;">as</span> <span style="color: black;"><em>varchar</em></span><span style="color: maroon;">(</span><span style="color: blue;">max</span><span style="color: maroon;">)</span><span style="color: maroon;">)</span> <span style="color: silver;">+</span> <span style="color: fuchsia;"><em>cast</em></span><span style="color: maroon;">(</span><span style="color: maroon;">PrevN</span> <span style="color: blue;">as</span> <span style="color: black;"><em>varchar</em></span><span style="color: maroon;">(</span><span style="color: blue;">max</span><span style="color: maroon;">)</span><span style="color: maroon;">)</span></p>
<p><span style="color: blue;">FROM</span> <span style="color: maroon;">Fibonacci</span></p>
<p><span style="color: blue;">FOR</span> <span style="color: blue;">XML</span> <span style="color: blue;">PATH</span><span style="color: maroon;">(</span><span style="color: red;">&#8221;</span><span style="color: maroon;">)</span><span style="color: maroon;">)</span><span style="color: silver;">,</span><span style="color: black;">3</span><span style="color: silver;">,</span><span style="color: black;">10000000</span><span style="color: maroon;">)</span> <span style="color: blue;">AS</span> <span style="color: maroon;">list</span></p>
</div>
</blockquote>
<p>Output&#8230;</p>
<p><a href="http://stevestedman.com/wp-content/uploads/2012/02/CTE_Fibonacci2.png"><img class="aligncenter size-full wp-image-1147" title="CTE_Fibonacci2" src="http://stevestedman.com/wp-content/uploads/2012/02/CTE_Fibonacci2.png" alt="" width="742" height="90" /></a></p>
<p>&nbsp;</p>
<p>What other classic math problems can you do with SQL Server.</p>
<p style="text-align: center;">
]]></content:encoded>
			<wfw:commentRss>http://stevestedman.com/2012/02/fibonacci-sequence/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Generating a Tree Path with a CTE</title>
		<link>http://stevestedman.com/2012/02/generating-a-tree-path-with-a-cte/</link>
		<comments>http://stevestedman.com/2012/02/generating-a-tree-path-with-a-cte/#comments</comments>
		<pubDate>Tue, 07 Feb 2012 13:32:11 +0000</pubDate>
		<dc:creator>SteveStedman</dc:creator>
				<category><![CDATA[CTE]]></category>
		<category><![CDATA[SQL Saturday]]></category>
		<category><![CDATA[Camping Tents]]></category>
		<category><![CDATA[Family Camping]]></category>
		<category><![CDATA[Sleeping Bags]]></category>

		<guid isPermaLink="false">http://stevestedman.com/?p=1130</guid>
		<description><![CDATA[The following example shows how to create a Tree Path with a Common Table Expression (CTE). First off what is a tree path? For this example I will be referring to the product categories at a camping and fitness store, where you have a top level with 4 categories, and some of the categories have [...]]]></description>
			<content:encoded><![CDATA[<p>The following example shows how to create a Tree Path with a Common Table Expression (<strong>CTE</strong>).</p>
<h2>First off what is a tree path?</h2>
<p>For this example I will be referring to the product categories at a camping and fitness store, where you have a top level with 4 categories, and some of the categories have subcategories:</p>
<ul>
<li>Camping</li>
<ul>
<li>Tents</li>
<ul>
<li>1 Person</li>
<li>2 Person</li>
<ul>
<li>Family Camping</li>
<li>Backpacking</li>
<li>Mountaineering</li>
</ul>
<li>3 Person</li>
<li>4 Person</li>
</ul>
<li>Backpacks</li>
<li>Sleeping Bags</li>
<li>Cooking</li>
</ul>
<li>Cycle</li>
<li>Snowsports</li>
<li>Fitness</li>
</ul>
<p>&nbsp;</p>
<p>In this example, the tree path for 2 person mountaineering tents would be  &#8221;Camping -&gt; Tents -&gt; 2 Person -&gt; Mountaineering&#8221;.  This is sometimes referred to as bread crumbs when you are creating a website or storefront.</p>
<p>&nbsp;</p>
<p>So how do you get from the following table structure into a hierarchy that includes the Tree Path.</p>
<p><a href="http://stevestedman.com/wp-content/uploads/2012/02/Tree_Path1.png"><img class="alignnone size-full wp-image-1133" style="border-image: initial; border-width: 1px; border-color: black; border-style: solid;" title="Tree_Path1" src="http://stevestedman.com/wp-content/uploads/2012/02/Tree_Path1.png" alt="" width="206" height="485" /></a></p>
<p>&nbsp;</p>
<p>You could do it by doing a self JOIN from the table back to itself, joining parent to id, which would work for 2 levels.  Then to go to the third or fourth level, you would need to another one or two self JOINs to get those levels in.  The problem with this strategy is that you are limited on the level of categories or the depth of the tree.</p>
<h2>Using a Common Table Expression</h2>
<p>The way that I would do it is with a CTE to get the following results.</p>
<p><a href="http://stevestedman.com/wp-content/uploads/2012/02/Tree_Path2.png"><img class="alignnone size-full wp-image-1134" style="border-image: initial; border-width: 1px; border-color: black; border-style: solid;" title="Tree_Path2" src="http://stevestedman.com/wp-content/uploads/2012/02/Tree_Path2.png" alt="" width="537" height="510" /></a></p>
<p>&nbsp;</p>
<p>Here is how you do it, with a recursive CTE, which will accommodate any number of levels up to 100 (even more if you specify a deeper MAXRECURSION).</p>
<p>&nbsp;</p>
<blockquote><p><span style="color: blue;">WITH</span> <span style="color: maroon;">departmentcte</span><span style="color: maroon;">(</span><span style="color: maroon;">deptid</span><span style="color: silver;">,</span> <span style="color: maroon;">department</span><span style="color: silver;">,</span> <span style="color: maroon;">parent</span><span style="color: silver;">,</span> <span style="color: blue;">LEVEL</span><span style="color: silver;">,</span> <span style="color: maroon;">treepath</span><span style="color: maroon;">)</span> <span style="color: blue;">AS</span></p>
<p><span style="color: maroon;">(</span> <span style="color: blue;">SELECT</span> <span style="color: maroon;">id</span> <span style="color: blue;">AS</span> <span style="color: maroon;">deptid</span><span style="color: silver;">,</span> <span style="color: maroon;">department</span><span style="color: silver;">,</span> <span style="color: maroon;">parent</span><span style="color: silver;">,</span> <span style="color: black;">0</span> <span style="color: blue;">AS</span> <span style="color: blue;">LEVEL</span><span style="color: silver;">,</span></p>
<p><span style="color: fuchsia;"><em>CAST</em></span><span style="color: maroon;">(</span><span style="color: maroon;">department</span> <span style="color: blue;">AS</span> <span style="color: black;"><em>VARCHAR</em></span><span style="color: maroon;">(</span><span style="color: black;">1024</span><span style="color: maroon;">)</span><span style="color: maroon;">)</span> <span style="color: blue;">AS</span> <span style="color: maroon;">treepath</span></p>
<p><span style="color: blue;">FROM</span> <span style="color: maroon;">departments</span></p>
<p><span style="color: blue;">WHERE</span> <span style="color: maroon;">parent</span> <span style="color: blue;">IS</span> <span style="color: blue;">NULL</span></p>
<p><span style="color: blue;">UNION</span> <span style="color: blue;">ALL</span> <span style="color: green;"><em>&#8211; and now for the recursive part </em></span></p>
<p><span style="color: blue;">SELECT</span> <span style="color: maroon;">d</span><span style="color: silver;">.</span><span style="color: maroon;">id</span> <span style="color: blue;">AS</span> <span style="color: maroon;">deptid</span><span style="color: silver;">,</span> <span style="color: maroon;">d</span><span style="color: silver;">.</span><span style="color: maroon;">department</span><span style="color: silver;">,</span> <span style="color: maroon;">d</span><span style="color: silver;">.</span><span style="color: maroon;">parent</span><span style="color: silver;">,</span></p>
<p><span style="color: maroon;">departmentcte</span><span style="color: silver;">.</span><span style="color: blue;">LEVEL</span> <span style="color: silver;">+</span> <span style="color: black;">1</span> <span style="color: blue;">AS</span> <span style="color: blue;">LEVEL</span><span style="color: silver;">,</span></p>
<p><span style="color: fuchsia;"><em>CAST</em></span><span style="color: maroon;">(</span><span style="color: maroon;">departmentcte</span><span style="color: silver;">.</span><span style="color: maroon;">treepath</span> <span style="color: silver;">+</span> <span style="color: red;">&#8216; -&gt; &#8217;</span> <span style="color: silver;">+</span></p>
<p><span style="color: fuchsia;"><em>CAST</em></span><span style="color: maroon;">(</span><span style="color: maroon;">d</span><span style="color: silver;">.</span><span style="color: maroon;">department</span> <span style="color: blue;">AS</span> <span style="color: black;"><em>VARCHAR</em></span><span style="color: maroon;">(</span><span style="color: black;">1024</span><span style="color: maroon;">)</span><span style="color: maroon;">)</span></p>
<p><span style="color: blue;">AS</span> <span style="color: black;"><em>VARCHAR</em></span><span style="color: maroon;">(</span><span style="color: black;">1024</span><span style="color: maroon;">)</span><span style="color: maroon;">)</span> <span style="color: blue;">AS</span> <span style="color: maroon;">treepath</span></p>
<p><span style="color: blue;">FROM</span> <span style="color: maroon;">departments</span> <span style="color: maroon;">d</span></p>
<p><span style="color: blue;">INNER</span> <span style="color: blue;">JOIN</span> <span style="color: maroon;">departmentcte</span></p>
<p><span style="color: blue;">ON</span> <span style="color: maroon;">departmentcte</span><span style="color: silver;">.</span><span style="color: maroon;">deptid</span> <span style="color: silver;">=</span> <span style="color: maroon;">d</span><span style="color: silver;">.</span><span style="color: maroon;">parent</span><span style="color: maroon;">)</span></p>
<p><span style="color: blue;">SELECT</span> <span style="color: silver;">*</span></p>
<p><span style="color: blue;">FROM</span> <span style="color: maroon;">departmentcte</span></p>
<p><span style="color: blue;">ORDER</span> <span style="color: blue;">BY</span> <span style="color: maroon;">treepath</span><span style="color: silver;">;</span></p></blockquote>
<p>Just another example of using a Recursive <a title="Common Table Expressions" href="http://stevestedman.com/tag/cte/">Common Table Expression</a>.</p>
<p>For more details, see my <a title="SQL Saturday 108 in Redmond WA" href="http://stevestedman.com/speaking/sql-saturday-108-in-redmond-wa/">CTE presentation at SQL Saturday in Redmond</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://stevestedman.com/2012/02/generating-a-tree-path-with-a-cte/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>CTE Query Performance</title>
		<link>http://stevestedman.com/2012/02/cte-query-performance/</link>
		<comments>http://stevestedman.com/2012/02/cte-query-performance/#comments</comments>
		<pubDate>Sun, 05 Feb 2012 20:51:18 +0000</pubDate>
		<dc:creator>SteveStedman</dc:creator>
				<category><![CDATA[CTE]]></category>
		<category><![CDATA[SQL Saturday]]></category>
		<category><![CDATA[SELECT]]></category>

		<guid isPermaLink="false">http://stevestedman.com/?p=1110</guid>
		<description><![CDATA[The following question came up when working on my CTE presentation for SQL Saturday. Does a query that JOINs a CTE to itself execute the CTE query once or twice? For instance:  ;WITH deptCTE(id, department, parent)     AS (SELECT id,department,parent FROM   Departments) SELECT q1.department,q2.department   FROM deptCTE q1  INNER JOIN deptCTE q2 ON q1.id = q2.parent  WHERE q1.parent IS NULL;  &#160; The following execution plan is produced showing that the Departments table is hit [...]]]></description>
			<content:encoded><![CDATA[<p>The following question came up when working on my <a title="Common Table Expressions (CTE)" href="http://stevestedman.com/consulting/virtual-classes/common-table-expressions-cte/">CTE presentation for SQL Saturday</a>.</p>
<div>Does a query that JOINs a CTE to itself execute the CTE query once or twice?</div>
<p>For instance:</p>
<blockquote><p><code><br />
<span style="color: blue;"> ;WITH</span> <span style="color: maroon;">deptCTE</span><span style="color: maroon;">(</span><span style="color: maroon;">id</span><span style="color: silver;">,</span> <span style="color: maroon;">department</span><span style="color: silver;">,</span> <span style="color: maroon;">parent</span><span style="color: maroon;">)</span><br />
<span style="color: blue;">    AS</span> <span style="color: maroon;">(</span><span style="color: blue;">SELECT</span> <span style="color: maroon;">id</span><span style="color: silver;">,</span><span style="color: maroon;">department</span><span style="color: silver;">,</span><span style="color: maroon;">parent</span><span> </span><span style="color: blue;">FROM</span>   <span style="color: maroon;">Departments</span><span style="color: maroon;">)</span><br />
<span style="color: blue;">SELECT</span> <span style="color: maroon;">q1</span><span style="color: silver;">.</span><span style="color: maroon;">department</span><span style="color: silver;">,</span><span style="color: maroon;">q2</span><span style="color: silver;">.</span><span style="color: maroon;">department</span><br />
<span style="color: blue;">  FROM</span> <span style="color: maroon;">deptCTE</span> <span style="color: maroon;">q1</span><br />
<span style="color: blue;"> INNER</span> <span style="color: blue;">JOIN</span> <span style="color: maroon;">deptCTE</span> <span style="color: maroon;">q2 </span><span style="color: blue;">ON</span> <span style="color: maroon;">q1</span><span style="color: silver;">.</span><span style="color: maroon;">id</span> <span style="color: silver;">=</span> <span style="color: maroon;">q2</span><span style="color: silver;">.</span><span style="color: maroon;">parent</span><br />
<span style="color: blue;"> WHERE</span> <span style="color: maroon;">q1</span><span style="color: silver;">.</span><span style="color: maroon;">parent</span> <span style="color: blue;">IS</span> <span style="color: blue;">NULL</span><span style="color: silver;">;</span> </code></p>
<p>&nbsp;</p></blockquote>
<p>The following execution plan is produced showing that the Departments table is hit twice with a table scan each time with the same cost.</p>
<p><a href="http://stevestedman.com/wp-content/uploads/2012/02/CTE_Execution_Plan.png"><img class="alignnone size-full wp-image-1128" style="border-image: initial; border-width: 1px; border-color: black; border-style: solid;" title="CTE_Execution_Plan" src="http://stevestedman.com/wp-content/uploads/2012/02/CTE_Execution_Plan.png" alt="" width="395" height="180" /></a></p>
<p>In the above example the query inside of the CTE gets run twice, and has no performance improvement over using the same query twice as a subquery. But it does clean up the syntax and reduce errors by only having the query in one place.</p>
]]></content:encoded>
			<wfw:commentRss>http://stevestedman.com/2012/02/cte-query-performance/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Sessions Submitted for SQL Saturday #120 Orange County CA</title>
		<link>http://stevestedman.com/2012/01/sessions-submitted-for-sql-saturday-120-orange-county-ca/</link>
		<comments>http://stevestedman.com/2012/01/sessions-submitted-for-sql-saturday-120-orange-county-ca/#comments</comments>
		<pubDate>Tue, 31 Jan 2012 01:06:03 +0000</pubDate>
		<dc:creator>SteveStedman</dc:creator>
				<category><![CDATA[Classes]]></category>
		<category><![CDATA[CTE]]></category>
		<category><![CDATA[Server Health]]></category>
		<category><![CDATA[SQL Saturday]]></category>
		<category><![CDATA[Orange County California]]></category>

		<guid isPermaLink="false">http://stevestedman.com/?p=1085</guid>
		<description><![CDATA[After being approved as a speaker at SQL Saturday 114 &#8211; Vancouver BC, and SQL Saturday 108 &#8211; Redmond WA, I have decided to give it another shot at SQL Saturday 120 in Orange County California. I have submitted 2 abstracts for sessions: The first one is titled Unleashing Common Table Expressions in SQL Server, and [...]]]></description>
			<content:encoded><![CDATA[<p>After being approved as a speaker at SQL Saturday 114 &#8211; Vancouver BC, and SQL Saturday 108 &#8211; Redmond WA, I have decided to give it another shot at SQL Saturday 120 in Orange County California.</p>
<p>I have submitted 2 abstracts for sessions:</p>
<p>The first one is titled <a title="Common Table Expressions (CTE)" href="http://stevestedman.com/consulting/virtual-classes/common-table-expressions-cte/">Unleashing Common Table Expressions in SQL Server</a>, and if accepted this will be the third time presenting this one on a SQL Saturday.</p>
<p>The next session which I will also be presenting in Vancouver BC is <a title="SQL Server Health" href="http://stevestedman.com/server-health/">Using SSRS reports to analyze SQL Server health</a>.</p>
<p>&nbsp;</p>
<p>I am looking forward to travelling to sunny southern California for these presentations.  Nice to get away from the <a title="Snow….." href="http://stevestedman.com/2012/01/960/">snow and rain</a> for a while.</p>
]]></content:encoded>
			<wfw:commentRss>http://stevestedman.com/2012/01/sessions-submitted-for-sql-saturday-120-orange-county-ca/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>SQL Server Developer Edition &#8211; Under $50</title>
		<link>http://stevestedman.com/2012/01/sql-server-developer-edition-under-50/</link>
		<comments>http://stevestedman.com/2012/01/sql-server-developer-edition-under-50/#comments</comments>
		<pubDate>Sun, 29 Jan 2012 23:30:36 +0000</pubDate>
		<dc:creator>SteveStedman</dc:creator>
				<category><![CDATA[Classes]]></category>
		<category><![CDATA[SQL]]></category>

		<guid isPermaLink="false">http://stevestedman.com/?p=1073</guid>
		<description><![CDATA[Having taught several Introduction to SQL Server classes, it is always a challenge for new users to get SQL Server running on their computer for the first time. I have seen cases where people attempt to download the 90 day trial, if that even exists any more, or to download SQL Express. Here is my [...]]]></description>
			<content:encoded><![CDATA[<table border="0">
<tbody>
<tr valign="top">
<td>Having taught several Introduction to SQL Server classes, it is always a challenge for new users to get SQL Server running on their computer for the first time. I have seen cases where people attempt to download the 90 day trial, if that even exists any more, or to download SQL Express. Here is my recommendation, for developers or anyone learning SQL Server if you need SQL Server on your laptop for a class or to just develop or try things out, then go for the SQL Server Developer Edition. SQL 2008 R2 developer edition is under $50 at Amazon.com.</p>
<p>My suggestion would be to go for the developer edition, it as all of the features of the full version and doesn&#8217;t expire after 90 days.</td>
<td><iframe style="width: 120px; height: 240px;" src="http://rcm.amazon.com/e/cm?lt1=_blank&amp;bc1=000000&amp;IS2=1&amp;bg1=FFFFFF&amp;fc1=000000&amp;lc1=0000FF&amp;t=wake2wakecom&amp;o=1&amp;p=8&amp;l=as4&amp;m=amazon&amp;f=ifr&amp;ref=ss_til&amp;asins=B003KWQBQ2" frameborder="0" marginwidth="0" marginheight="0" scrolling="no" width="320" height="240"></iframe></td>
</tr>
</tbody>
</table>
]]></content:encoded>
			<wfw:commentRss>http://stevestedman.com/2012/01/sql-server-developer-edition-under-50/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Session Accepted For SQL Saturday 108 in Redmond</title>
		<link>http://stevestedman.com/2012/01/session-accepted-for-sql-saturday-108-in-redmond/</link>
		<comments>http://stevestedman.com/2012/01/session-accepted-for-sql-saturday-108-in-redmond/#comments</comments>
		<pubDate>Sun, 29 Jan 2012 20:46:45 +0000</pubDate>
		<dc:creator>SteveStedman</dc:creator>
				<category><![CDATA[CTE]]></category>
		<category><![CDATA[SQL Saturday]]></category>

		<guid isPermaLink="false">http://stevestedman.com/?p=1064</guid>
		<description><![CDATA[I just checked the schedule and one of the sessions that I submitted for SQL Saturday 108 in Redmond WA on February 25th has been accepted. I will be presenting Unleashing Common Table Expressions in SQL Server. If you are going to be there, drop me an email and let me know. This should be fun!]]></description>
			<content:encoded><![CDATA[<p><a href="http://stevestedman.com/wp-content/uploads/2012/01/eventhome.png"><img class="alignright size-full wp-image-1140" title="SQLSatRedmond" src="http://stevestedman.com/wp-content/uploads/2012/01/eventhome.png" alt="" width="236" height="115" /></a>I just checked the schedule and one of the sessions that I submitted for <a title="Speaking" href="http://stevestedman.com/speaking/">SQL Saturday 108 in Redmond WA</a> on February 25th has been accepted.</p>
<p>I will be presenting <a title="Common Table Expressions (CTE)" href="http://stevestedman.com/consulting/virtual-classes/common-table-expressions-cte/">Unleashing Common Table Expressions in SQL Server</a>.</p>
<p>If you are going to be there, drop me an email and let me know.</p>
<p>This should be fun!</p>
]]></content:encoded>
			<wfw:commentRss>http://stevestedman.com/2012/01/session-accepted-for-sql-saturday-108-in-redmond/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

