<?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>youdidwhatwithtsql.com &#187; SQL Server 2008</title>
	<atom:link href="http://www.youdidwhatwithtsql.com/tag/sql-server-2008/feed" rel="self" type="application/rss+xml" />
	<link>http://www.youdidwhatwithtsql.com</link>
	<description>making DBAs everywhere curse!</description>
	<lastBuildDate>Tue, 31 Jan 2012 12:21:23 +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>Windows Server 2008 64 Bit on VirtualBox installation issue.</title>
		<link>http://www.youdidwhatwithtsql.com/windows-server-2008-64-bit-on-virtualbox-installation-issue/927</link>
		<comments>http://www.youdidwhatwithtsql.com/windows-server-2008-64-bit-on-virtualbox-installation-issue/927#comments</comments>
		<pubDate>Wed, 05 Jan 2011 21:18:26 +0000</pubDate>
		<dc:creator>Rhys</dc:creator>
				<category><![CDATA[Windows]]></category>
		<category><![CDATA[Clustering]]></category>
		<category><![CDATA[SQL Server 2008]]></category>
		<category><![CDATA[VirtualBox]]></category>
		<category><![CDATA[Windows 2008]]></category>

		<guid isPermaLink="false">http://www.youdidwhatwithtsql.com/windows-server-2008-64-bit-on-virtualbox-installation-issue/927</guid>
		<description><![CDATA[I&#8217;m just starting to explore SQL Server 2008 Clustering and hit this issue when trying to install Windows Server 2008 (64 Bit) in VirtualBox. The below screen, with &#34;Windows failed to start&#34; error, reared its ugly head shortly after booting off the ISO image. Thankfully the solution is quick and easy (once you&#8217;ve found it) [...]<p>Post from: <a href="http://www.youdidwhatwithtsql.com">youdidwhatwithtsql.com</a><br/><br/><a href="http://www.youdidwhatwithtsql.com/windows-server-2008-64-bit-on-virtualbox-installation-issue/927">Windows Server 2008 64 Bit on VirtualBox installation issue.</a></p>
]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m just starting to explore <a title="SQL Server 2008 Clustering" href="http://msdn.microsoft.com/en-us/library/ms189134.aspx" target="_blank">SQL Server 2008 Clustering</a> and hit this issue when trying to install Windows Server 2008 (64 Bit) in <a title="VirtualBox" href="http://www.virtualbox.org/" target="_blank">VirtualBox</a>. The below screen, with &quot;Windows failed to start&quot; error, reared its ugly head shortly after booting off the ISO image.</p>
<p><a href="http://www.youdidwhatwithtsql.com/wp-content/uploads/2011/01/virtualbox_windows_failed_to_start.png"><img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="virtualbox_windows_failed_to_start" border="0" alt="virtualbox windows failed to start thumb Windows Server 2008 64 Bit on VirtualBox installation issue." src="http://www.youdidwhatwithtsql.com/wp-content/uploads/2011/01/virtualbox_windows_failed_to_start_thumb.png" width="644" height="422" /></a></p>
<p>Thankfully the solution is quick and easy (once you&#8217;ve found it) so I&#8217;m posting it here for clarity.</p>
<p>Close the virtual machine and return to the main VirtualBox screen.</p>
<p><a href="http://www.youdidwhatwithtsql.com/wp-content/uploads/2011/01/VirtualBox.png"><img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="VirtualBox" border="0" alt="VirtualBox thumb Windows Server 2008 64 Bit on VirtualBox installation issue." src="http://www.youdidwhatwithtsql.com/wp-content/uploads/2011/01/VirtualBox_thumb.png" width="644" height="483" /></a></p>
<p>Select the appropriate virtual machine and click the <strong>Settings </strong>button. Click the <strong>System</strong> icon on the left and check the box labelled <strong>&quot;Enable IO APIC&quot; </strong>on the <strong>Motherboard </strong>tab.</p>
<p><a href="http://www.youdidwhatwithtsql.com/wp-content/uploads/2011/01/io_apic.png"><img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="io_apic" border="0" alt="io apic thumb Windows Server 2008 64 Bit on VirtualBox installation issue." src="http://www.youdidwhatwithtsql.com/wp-content/uploads/2011/01/io_apic_thumb.png" width="644" height="472" /></a></p>
<p>Click the <strong>Processor</strong> tab and check the box labelled <strong>&quot;Enable PAE/NX&quot;</strong>.</p>
<p><a href="http://www.youdidwhatwithtsql.com/wp-content/uploads/2011/01/pae_nx.png"><img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="pae_nx" border="0" alt="pae nx thumb Windows Server 2008 64 Bit on VirtualBox installation issue." src="http://www.youdidwhatwithtsql.com/wp-content/uploads/2011/01/pae_nx_thumb.png" width="644" height="472" /></a></p>
<p>Click OK to save the changes and restart the virtual machine. Your installation of Windows 2008 Server (64 Bit) should now progress. Fix for this dug out of a <a title="VirtualBox forums" href="http://forums.virtualbox.org/viewtopic.php?f=2&amp;t=9280" target="_blank">VirtualBox forum thread</a>.</p>
<p><map name='google_ad_map_927_a45beff5d2e172f6'>
<area shape='rect' href='http://imageads.googleadservices.com/pagead/imgclick/927?pos=0' coords='1,2,367,28' />
<area shape='rect' href='http://services.google.com/feedback/abg' coords='384,10,453,23'/></map>
<img usemap='#google_ad_map_927_a45beff5d2e172f6' border='0' src='http://imageads.googleadservices.com/pagead/ads?format=468x30_aff_img&amp;client=&amp;channel=&amp;output=png&amp;cuid=927&amp;url=http%3A%2F%2Fwww.youdidwhatwithtsql.com%2Fwindows-server-2008-64-bit-on-virtualbox-installation-issue%2F927' title="Windows Server 2008 64 Bit on VirtualBox installation issue." alt=" Windows Server 2008 64 Bit on VirtualBox installation issue." /></p><p>Post from: <a href="http://www.youdidwhatwithtsql.com">youdidwhatwithtsql.com</a><br/><br/><a href="http://www.youdidwhatwithtsql.com/windows-server-2008-64-bit-on-virtualbox-installation-issue/927">Windows Server 2008 64 Bit on VirtualBox installation issue.</a></p>
<div class="none"><div class="g-plusone" data-href="http://www.youdidwhatwithtsql.com/windows-server-2008-64-bit-on-virtualbox-installation-issue/927" size="standard" count="true"></div></div>]]></content:encoded>
			<wfw:commentRss>http://www.youdidwhatwithtsql.com/windows-server-2008-64-bit-on-virtualbox-installation-issue/927/feed</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>SSIS: Don&#8217;t run the process on a bank Holiday</title>
		<link>http://www.youdidwhatwithtsql.com/ssis-dont-run-the-process-on-a-bank-holiday/452</link>
		<comments>http://www.youdidwhatwithtsql.com/ssis-dont-run-the-process-on-a-bank-holiday/452#comments</comments>
		<pubDate>Sat, 21 Nov 2009 20:45:13 +0000</pubDate>
		<dc:creator>Rhys</dc:creator>
				<category><![CDATA[SSIS]]></category>
		<category><![CDATA[Bank Holidays]]></category>
		<category><![CDATA[SQL Server 2008]]></category>

		<guid isPermaLink="false">http://www.youdidwhatwithtsql.com/ssis-dont-run-the-process-on-a-bank-holiday/452</guid>
		<description><![CDATA[Sadly, as people don&#8217;t make sense, we have to make compromises in our systems and processes. I recently had a requirement, in an SSIS package, to be able to identify which days were Bank Holidays and take a different course of action, e.g. not run the main process. Here&#8217;s an illustration of the approach I [...]<p>Post from: <a href="http://www.youdidwhatwithtsql.com">youdidwhatwithtsql.com</a><br/><br/><a href="http://www.youdidwhatwithtsql.com/ssis-dont-run-the-process-on-a-bank-holiday/452">SSIS: Don&#8217;t run the process on a bank Holiday</a></p>
]]></description>
			<content:encoded><![CDATA[<p>Sadly, as people don&#8217;t make sense, we have to make compromises in our systems and processes. I recently had a requirement, in an <a href="http://msdn.microsoft.com/en-us/library/ms141026.aspx" target="_blank">SSIS</a> package, to be able to identify which days were Bank Holidays and take a different course of action, e.g. not run the main process. Here&#8217;s an illustration of the approach I took using a simple lookup table, containing holiday dates, and SSIS <a href="http://technet.microsoft.com/en-us/library/ms141261.aspx" target="_blank">precedence constraints</a>.</p>
<p>The TSQL (<a href="http://www.microsoft.com/sqlserver/2008/en/us/default.aspx" target="_blank">SQL Server</a> 2008) below will create a table called <strong>BankHolidays</strong> and populate the table with public holidays up to the end of 2010. The Bank Holiday dates have been taken from the <a href="http://www.direct.gov.uk/en/Governmentcitizensandrights/LivingintheUK/DG_073741" target="_blank">DirectGov</a> site and are for England &amp; Wales only. Depending on your requirements you may want to consider dates, like Christmas, that fall on a weekend. These technically aren&#8217;t Bank Holidays so haven&#8217;t been included here, but you may wish to add them if you don&#8217;t want to run on these days.</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p452code4'); return false;">View Code</a> TSQL</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p4524"><td class="code" id="p452code4"><pre class="tsql" style="font-family:monospace;"><span style="color: #008080;">-- Create a table to contain Bank Holidays</span>
<span style="color: #0000FF;">CREATE</span> <span style="color: #0000FF;">TABLE</span> dbo.<span style="color: #202020;">BankHolidays</span>
<span style="color: #808080;">&#40;</span>
	BankHoliday <span style="color: #0000FF;">DATE</span> <span style="color: #808080;">NOT</span> <span style="color: #808080;">NULL</span> <span style="color: #0000FF;">PRIMARY</span> <span style="color: #0000FF;">KEY</span> <span style="color: #0000FF;">CLUSTERED</span>,
	ActiVe <span style="color: #0000FF;">BIT</span> <span style="color: #808080;">NOT</span> <span style="color: #808080;">NULL</span> <span style="color: #0000FF;">DEFAULT</span> <span style="color: #000;">1</span>
<span style="color: #808080;">&#41;</span>;
GO
&nbsp;
<span style="color: #0000FF;">INSERT</span> <span style="color: #0000FF;">INTO</span> dbo.<span style="color: #202020;">BankHolidays</span>
<span style="color: #808080;">&#40;</span>
	BankHoliday
<span style="color: #808080;">&#41;</span>
<span style="color: #0000FF;">VALUES</span>
<span style="color: #808080;">&#40;</span>
	<span style="color: #FF0000;">'2009-12-25'</span>
<span style="color: #808080;">&#41;</span>,
<span style="color: #808080;">&#40;</span>
	<span style="color: #FF0000;">'2009-12-28'</span>
<span style="color: #808080;">&#41;</span>,
<span style="color: #808080;">&#40;</span>
	<span style="color: #FF0000;">'2010-01-01'</span>
<span style="color: #808080;">&#41;</span>,
<span style="color: #808080;">&#40;</span>
	<span style="color: #FF0000;">'2010-04-02'</span>
<span style="color: #808080;">&#41;</span>,
<span style="color: #808080;">&#40;</span>
	<span style="color: #FF0000;">'2010-04-05'</span>
<span style="color: #808080;">&#41;</span>,
<span style="color: #808080;">&#40;</span>
	<span style="color: #FF0000;">'2010-05-03'</span>
<span style="color: #808080;">&#41;</span>,
<span style="color: #808080;">&#40;</span>
	<span style="color: #FF0000;">'2010-05-31'</span>
<span style="color: #808080;">&#41;</span>,
<span style="color: #808080;">&#40;</span>
	<span style="color: #FF0000;">'2010-08-30'</span>
<span style="color: #808080;">&#41;</span>,
<span style="color: #808080;">&#40;</span>
	<span style="color: #FF0000;">'2010-12-27'</span>
<span style="color: #808080;">&#41;</span>,
<span style="color: #808080;">&#40;</span>
	<span style="color: #FF0000;">'2010-12-28'</span>
<span style="color: #808080;">&#41;</span>;
GO</pre></td></tr></table></div>

<p>Note the <strong>Active</strong> flag in the table. This is just in case we need to deactivate a Bank Holiday for some some reason. Added flexibility is always useful.</p>
<p>Launch <a href="http://msdn.microsoft.com/en-us/library/ms173767.aspx" target="_blank">BIDS</a> and create a new <a href="http://www.microsoft.com/sqlserver/2005/en/us/integration-services.aspx" target="_blank">SSIS</a> project. The first thing we need to do is add a variable called <strong>BankHoliday</strong>. We will use this in determining whether the day is a Bank Holiday or not. Add an Int32 variable in the <a href="http://www.microsoft.com/sqlserver/2005/en/us/integration-services.aspx" target="_blank">SSIS</a> variables window, as illustrated below.</p>
<p><a href="http://www.youdidwhatwithtsql.com/wp-content/uploads/2009/11/ssis_bank_holiday_variable.png"><img style="display: inline; border-width: 0px;" title="ssis bank holiday variable" src="http://www.youdidwhatwithtsql.com/wp-content/uploads/2009/11/ssis_bank_holiday_variable_thumb.png" border="0" alt="ssis bank holiday variable thumb SSIS: Dont run the process on a bank Holiday" width="644" height="167" /></a></p>
<p>Add an <a href="http://msdn.microsoft.com/en-us/library/ms141013.aspx" target="_blank">OLE DB connection</a> that points at the database containing the <strong>BankHolidays</strong> table. Drop an <a href="http://technet.microsoft.com/en-us/library/ms141003.aspx" target="_blank">Execute SQL task</a> from the toolbox onto the design canvas. Right click the task and click edit to configure the task properties. Add the OLE DB connection manager to <strong>Connection </strong>and the below TSQL to <strong>SQLStatement</strong>.</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p452code5'); return false;">View Code</a> TSQL</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p4525"><td class="code" id="p452code5"><pre class="tsql" style="font-family:monospace;"><span style="color: #0000FF;">SELECT</span> <span style="color: #FF00FF;">COUNT</span><span style="color: #808080;">&#40;</span><span style="color: #808080;">*</span><span style="color: #808080;">&#41;</span>
<span style="color: #0000FF;">FROM</span> dbo.<span style="color: #202020;">BankHolidays</span>
<span style="color: #0000FF;">WHERE</span> BankHoliday <span style="color: #808080;">=</span> <span style="color: #0000FF;">CONVERT</span><span style="color: #808080;">&#40;</span><span style="color: #0000FF;">DATE</span>, <span style="color: #FF00FF;">GETDATE</span><span style="color: #808080;">&#40;</span><span style="color: #808080;">&#41;</span><span style="color: #808080;">&#41;</span>
<span style="color: #808080;">AND</span> Active <span style="color: #808080;">=</span> <span style="color: #000;">1</span>;</pre></td></tr></table></div>

<p><strong>ResultSet</strong> should be changed to &#8220;Single row&#8221;.</p>
<p><a href="http://www.youdidwhatwithtsql.com/wp-content/uploads/2009/11/Execute_SQL_Task_Bank_Holidays.png"><img style="display: inline; border-width: 0px;" title="Execute SQL Task Bank Holidays" src="http://www.youdidwhatwithtsql.com/wp-content/uploads/2009/11/Execute_SQL_Task_Bank_Holidays_thumb.png" border="0" alt="Execute SQL Task Bank Holidays thumb SSIS: Dont run the process on a bank Holiday" width="244" height="208" /></a></p>
<p><strong>UPDATE:</strong> (Thanks to Dr Drew in the comments for pointing this omission out.)</p>
<p>Click on the <strong>Result Set </strong>tab and map the variable <strong>BankHoliday</strong> as shown below. This variable mapping will be used to determine if the execution date is a bank holiday.</p>
<p><a href="http://www.youdidwhatwithtsql.com/wp-content/uploads/2009/11/resultset_mapping_bank_holiday.png"><img class="alignnone size-medium wp-image-859" title="resultset mapping bankholiday variable" src="http://www.youdidwhatwithtsql.com/wp-content/uploads/2009/11/resultset_mapping_bank_holiday-300x254.png" alt="resultset mapping bank holiday 300x254 SSIS: Dont run the process on a bank Holiday" width="300" height="254" /></a></p>
<p>Now drop two <a href="http://msdn.microsoft.com/en-us/library/ms141752.aspx" target="_blank">Script Task</a> components onto the design canvas and connect them from the Execute SQL Task. Call one &#8220;Display &#8220;Not Bank Holiday&#8221; message&#8221; and the other &#8220;Display &#8220;It&#8217;s a Bank Holiday&#8221; message&#8221;. This should look something like this.</p>
<p><a href="http://www.youdidwhatwithtsql.com/wp-content/uploads/2009/11/ssis_design_canvas.png"><img style="display: inline; border-width: 0px;" title="ssis design canvas" src="http://www.youdidwhatwithtsql.com/wp-content/uploads/2009/11/ssis_design_canvas_thumb.png" border="0" alt="ssis design canvas thumb SSIS: Dont run the process on a bank Holiday" width="244" height="91" /></a></p>
<p>Next we need to edit the constraints connecting our Script tasks to implement the logic to determine if it is a Bank Holiday or not. Right click the constraint connecting the script task called &#8220;Display &#8220;Not Bank Holiday&#8221; message&#8221; and choose Edit. Change &#8220;Evaluation Operation&#8221; to &#8216;Expression and Constraint&#8217; and enter the following expression into the appropriate text box; @BankHoliday == 0. Finally click the radio button labelled &#8220;Logical OR&#8221;. This should look like this&#8230;</p>
<p><a href="http://www.youdidwhatwithtsql.com/wp-content/uploads/2009/11/Bank_Holiday_Constraint_1.png"><img style="display: inline; border: 0px;" title="Bank_Holiday_Constraint_1" src="http://www.youdidwhatwithtsql.com/wp-content/uploads/2009/11/Bank_Holiday_Constraint_1_thumb.png" border="0" alt="Bank Holiday Constraint 1 thumb SSIS: Dont run the process on a bank Holiday" width="644" height="481" /></a></p>
<p>Click OK to save your changes. Now we need to edit the constraint connected to the Script Task called &#8220;Display &#8220;It&#8217;s a Bank Holiday&#8221; message&#8221;. The setup here is exactly the same except for the Expression which should be entered as @BankHoliday == 1.</p>
<p><a href="http://www.youdidwhatwithtsql.com/wp-content/uploads/2009/11/Bank_Holiday_Constraint_2.png"><img style="display: inline; border: 0px;" title="Bank_Holiday_Constraint_2" src="http://www.youdidwhatwithtsql.com/wp-content/uploads/2009/11/Bank_Holiday_Constraint_2_thumb.png" border="0" alt="Bank Holiday Constraint 2 thumb SSIS: Dont run the process on a bank Holiday" width="644" height="481" /></a></p>
<p>By now your design canvas should look something like below.</p>
<p><a href="http://www.youdidwhatwithtsql.com/wp-content/uploads/2009/11/ssis_design_canvas_2.png"><img style="display: inline; border: 0px;" title="ssis_design_canvas_2" src="http://www.youdidwhatwithtsql.com/wp-content/uploads/2009/11/ssis_design_canvas_2_thumb.png" border="0" alt="ssis design canvas 2 thumb SSIS: Dont run the process on a bank Holiday" width="244" height="90" /></a></p>
<p>Finally we&#8217;re just going to add a little code to each script task to display a message box. In the script task called &#8220;Display &#8220;Not Bank Holiday&#8221; message&#8221; click edit, go to the script tab, and click the &#8220;Design Script button&#8221;. Add the below code.</p>
<pre lang="VB.Net">Imports System
Imports System.Data
Imports System.Math
Imports Microsoft.SqlServer.Dts.Runtime

Public Class ScriptMain

    Public Sub Main()
        MsgBox("Hi, today is not a Bank Holiday, get back to work!")
        Dts.TaskResult = Dts.Results.Success
    End Sub

End Class</pre>
<p>In the script task called &#8220;Display &#8220;It&#8217;s a Bank Holiday&#8221; message&#8221; add the below code.</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p452code6'); return false;">View Code</a> TSQL</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p4526"><td class="code" id="p452code6"><pre class="tsql" style="font-family:monospace;">Imports System
Imports System.<span style="color: #0000FF;">Data</span>
Imports System.<span style="color: #202020;">Math</span>
Imports Microsoft.<span style="color: #202020;">SqlServer</span>.<span style="color: #202020;">Dts</span>.<span style="color: #202020;">Runtime</span>
&nbsp;
<span style="color: #0000FF;">Public</span> <span style="color: #0000FF;">Class</span> ScriptMain
&nbsp;
	<span style="color: #0000FF;">Public</span> Sub Main<span style="color: #808080;">&#40;</span><span style="color: #808080;">&#41;</span>
        MsgBox<span style="color: #808080;">&#40;</span><span style="color: #FF0000;">&quot;Hi, today is a Bank Holiday, put your feet up!&quot;</span><span style="color: #808080;">&#41;</span>
		Dts.<span style="color: #202020;">TaskResult</span> <span style="color: #808080;">=</span> Dts.<span style="color: #202020;">Results</span>.<span style="color: #202020;">Success</span>
	<span style="color: #0000FF;">End</span> Sub
&nbsp;
<span style="color: #0000FF;">End</span> <span style="color: #0000FF;">Class</span></pre></td></tr></table></div>

<p>Now we should be ready to execute the package. Click run and you should see the following message (assuming it&#8217;s not a bank holiday!).</p>
<p><a href="http://www.youdidwhatwithtsql.com/wp-content/uploads/2009/11/not_a_bank_holiday.png"><img style="display: inline; border: 0px;" title="not_a_bank_holiday" src="http://www.youdidwhatwithtsql.com/wp-content/uploads/2009/11/not_a_bank_holiday_thumb.png" border="0" alt="not a bank holiday thumb SSIS: Dont run the process on a bank Holiday" width="244" height="113" /></a></p>
<p>Now, either wait until a bank holiday occurs, or change the date on your computer to one contained in the <strong>BankHolidays</strong> table. I changed mine to 2009-12-28 and here&#8217;s what I saw when I executed the package.</p>
<p><a href="http://www.youdidwhatwithtsql.com/wp-content/uploads/2009/11/bank_holiday.png"><img style="display: inline; border: 0px;" title="bank_holiday" src="http://www.youdidwhatwithtsql.com/wp-content/uploads/2009/11/bank_holiday_thumb.png" border="0" alt="bank holiday thumb SSIS: Dont run the process on a bank Holiday" width="244" height="123" /></a></p>
<p><map name='google_ad_map_452_a45beff5d2e172f6'>
<area shape='rect' href='http://imageads.googleadservices.com/pagead/imgclick/452?pos=0' coords='1,2,367,28' />
<area shape='rect' href='http://services.google.com/feedback/abg' coords='384,10,453,23'/></map>
<img usemap='#google_ad_map_452_a45beff5d2e172f6' border='0' src='http://imageads.googleadservices.com/pagead/ads?format=468x30_aff_img&amp;client=&amp;channel=&amp;output=png&amp;cuid=452&amp;url=http%3A%2F%2Fwww.youdidwhatwithtsql.com%2Fssis-dont-run-the-process-on-a-bank-holiday%2F452' title="SSIS: Dont run the process on a bank Holiday" alt=" SSIS: Dont run the process on a bank Holiday" /></p><p>Post from: <a href="http://www.youdidwhatwithtsql.com">youdidwhatwithtsql.com</a><br/><br/><a href="http://www.youdidwhatwithtsql.com/ssis-dont-run-the-process-on-a-bank-holiday/452">SSIS: Don&#8217;t run the process on a bank Holiday</a></p>
<div class="none"><div class="g-plusone" data-href="http://www.youdidwhatwithtsql.com/ssis-dont-run-the-process-on-a-bank-holiday/452" size="standard" count="true"></div></div>]]></content:encoded>
			<wfw:commentRss>http://www.youdidwhatwithtsql.com/ssis-dont-run-the-process-on-a-bank-holiday/452/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Testing datetime dependent Stored Procedures</title>
		<link>http://www.youdidwhatwithtsql.com/testing-datetime-dependent-stored-procedures/433</link>
		<comments>http://www.youdidwhatwithtsql.com/testing-datetime-dependent-stored-procedures/433#comments</comments>
		<pubDate>Sat, 14 Nov 2009 14:24:28 +0000</pubDate>
		<dc:creator>Rhys</dc:creator>
				<category><![CDATA[T-SQL]]></category>
		<category><![CDATA[sql server 2005]]></category>
		<category><![CDATA[SQL Server 2008]]></category>
		<category><![CDATA[TSQL]]></category>

		<guid isPermaLink="false">http://www.youdidwhatwithtsql.com/testing-datetime-dependent-stored-procedures/433</guid>
		<description><![CDATA[This week I was tasked with testing a stored procedure that was meant to output data on certain days. This was over a 120 day period, so I wanted to find some automated way of doing this, rather than changing the server date manually for each execution. The method I came up with involves the [...]<p>Post from: <a href="http://www.youdidwhatwithtsql.com">youdidwhatwithtsql.com</a><br/><br/><a href="http://www.youdidwhatwithtsql.com/testing-datetime-dependent-stored-procedures/433">Testing datetime dependent Stored Procedures</a></p>
]]></description>
			<content:encoded><![CDATA[<p>This week I was tasked with testing a stored procedure that was meant to output data on certain days. This was over a 120 day period, so I wanted to find some automated way of doing this, rather than changing the server date manually for each execution. The method I came up with involves the use of <a href="http://msdn.microsoft.com/en-us/library/ms175046.aspx" target="_blank">xp_cmdshell</a> to execute the <a href="http://en.wikipedia.org/wiki/List_of_DOS_commands#time_and_date" target="_blank">date command</a>. Here&#8217;s an illustration of what I came up with.</p>
<p>First create this stored procedure. This will just check to see if it&#8217;s Saturday and output &quot;Yes&quot; if it is.</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p433code9'); return false;">View Code</a> TSQL</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p4339"><td class="code" id="p433code9"><pre class="tsql" style="font-family:monospace;"><span style="color: #0000FF;">SET</span> ANSI_<span style="color: #808080;">NULL</span>S <span style="color: #0000FF;">ON</span>
GO
<span style="color: #0000FF;">SET</span> QUOTED_IDENTIFIER <span style="color: #0000FF;">ON</span>
GO
<span style="color: #008080;">-- =============================================</span>
<span style="color: #008080;">-- Author: Rhys Campbell</span>
<span style="color: #008080;">-- Create date: 2009-11-14</span>
<span style="color: #008080;">-- Description:	Outputs &quot;Yes&quot; if it is Saturday</span>
<span style="color: #008080;">-- otherwise &quot;No&quot;</span>
<span style="color: #008080;">-- =============================================</span>
<span style="color: #0000FF;">CREATE</span> <span style="color: #0000FF;">PROCEDURE</span> usp_isItSaturday
<span style="color: #0000FF;">AS</span>
<span style="color: #0000FF;">BEGIN</span>
	<span style="color: #0000FF;">SET</span> <span style="color: #0000FF;">NOCOUNT</span> <span style="color: #0000FF;">ON</span>;
&nbsp;
	<span style="color: #0000FF;">DECLARE</span> @isItSaturday <span style="color: #0000FF;">VARCHAR</span><span style="color: #808080;">&#40;</span><span style="color: #000;">3</span><span style="color: #808080;">&#41;</span>;
&nbsp;
    	<span style="color: #0000FF;">SET</span> @isItSaturday <span style="color: #808080;">=</span> <span style="color: #0000FF;">CASE</span>
				<span style="color: #0000FF;">WHEN</span> <span style="color: #FF00FF;">DATEPART</span><span style="color: #808080;">&#40;</span>dw, <span style="color: #FF00FF;">GETDATE</span><span style="color: #808080;">&#40;</span><span style="color: #808080;">&#41;</span><span style="color: #808080;">&#41;</span> <span style="color: #808080;">=</span> <span style="color: #000;">7</span> <span style="color: #0000FF;">THEN</span> <span style="color: #FF0000;">'Yes'</span>
				<span style="color: #0000FF;">ELSE</span>
					<span style="color: #FF0000;">'No'</span>
			    <span style="color: #0000FF;">END</span>;
	<span style="color: #0000FF;">SELECT</span> <span style="color: #FF00FF;">GETDATE</span><span style="color: #808080;">&#40;</span><span style="color: #808080;">&#41;</span>, @isItSaturday;
&nbsp;
<span style="color: #0000FF;">END</span>
GO</pre></td></tr></table></div>

<p>The script below will change the date by one day, then execute usp_isItSaturday, in sequence up to the end of 2009. I had to introduce the <a href="http://msdn.microsoft.com/en-us/library/ms187331.aspx" target="_blank">WAITFOR</a> delay because <a href="http://www.microsoft.com/sqlserver/2008/en/us/default.aspx" target="_blank">SQL Server</a> seems to take a few seconds to register the date change. The script will simply loop until the day changes before executing the store procedure.</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p433code10'); return false;">View Code</a> TSQL</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p43310"><td class="code" id="p433code10"><pre class="tsql" style="font-family:monospace;"><span style="color: #008080;">-- Enable xp_cmdshell</span>
<span style="color: #0000FF;">EXEC</span> master.<span style="color: #202020;">dbo</span>.<span style="color: #AF0000;">sp_configure</span> <span style="color: #FF0000;">'xp_cmdshell'</span>, <span style="color: #000;">1</span>;
<span style="color: #0000FF;">RECONFIGURE</span>;
&nbsp;
<span style="color: #0000FF;">DECLARE</span> @command <span style="color: #0000FF;">VARCHAR</span><span style="color: #808080;">&#40;</span><span style="color: #000;">4000</span><span style="color: #808080;">&#41;</span>,
		@<span style="color: #0000FF;">date</span> <span style="color: #0000FF;">VARCHAR</span><span style="color: #808080;">&#40;</span><span style="color: #000;">10</span><span style="color: #808080;">&#41;</span>,
		@starting <span style="color: #0000FF;">DATETIME</span>,
		@<span style="color: #0000FF;">day</span> <span style="color: #0000FF;">INTEGER</span>;
&nbsp;
<span style="color: #0000FF;">SET</span> @starting <span style="color: #808080;">=</span> <span style="color: #FF00FF;">GETDATE</span><span style="color: #808080;">&#40;</span><span style="color: #808080;">&#41;</span>;
&nbsp;
<span style="color: #0000FF;">WHILE</span> <span style="color: #808080;">&#40;</span>@starting <span style="color: #808080;">&lt;=</span> <span style="color: #FF0000;">'2009-12-31T00:00:00'</span><span style="color: #808080;">&#41;</span>
<span style="color: #0000FF;">BEGIN</span>
&nbsp;
	<span style="color: #0000FF;">SET</span> @<span style="color: #0000FF;">date</span> <span style="color: #808080;">=</span> <span style="color: #0000FF;">CAST</span><span style="color: #808080;">&#40;</span><span style="color: #FF00FF;">DATEPART</span><span style="color: #808080;">&#40;</span>d, @starting<span style="color: #808080;">&#41;</span> <span style="color: #0000FF;">AS</span> <span style="color: #0000FF;">VARCHAR</span><span style="color: #808080;">&#40;</span><span style="color: #000;">2</span><span style="color: #808080;">&#41;</span><span style="color: #808080;">&#41;</span> <span style="color: #808080;">+</span> <span style="color: #FF0000;">'/'</span> <span style="color: #808080;">+</span> <span style="color: #0000FF;">CAST</span><span style="color: #808080;">&#40;</span><span style="color: #FF00FF;">DATEPART</span><span style="color: #808080;">&#40;</span>m, @starting<span style="color: #808080;">&#41;</span> <span style="color: #0000FF;">AS</span> <span style="color: #0000FF;">VARCHAR</span><span style="color: #808080;">&#40;</span><span style="color: #000;">2</span><span style="color: #808080;">&#41;</span><span style="color: #808080;">&#41;</span> <span style="color: #808080;">+</span> <span style="color: #FF0000;">'/'</span> <span style="color: #808080;">+</span> <span style="color: #0000FF;">CAST</span><span style="color: #808080;">&#40;</span><span style="color: #FF00FF;">DATEPART</span><span style="color: #808080;">&#40;</span>YYYY, @starting<span style="color: #808080;">&#41;</span> <span style="color: #0000FF;">AS</span> <span style="color: #0000FF;">VARCHAR</span><span style="color: #808080;">&#40;</span><span style="color: #000;">4</span><span style="color: #808080;">&#41;</span><span style="color: #808080;">&#41;</span>;
	<span style="color: #008080;">-- Get the day for tracking when the date change has taken effect</span>
	<span style="color: #0000FF;">SET</span> @<span style="color: #0000FF;">day</span> <span style="color: #808080;">=</span> <span style="color: #FF00FF;">DATEPART</span><span style="color: #808080;">&#40;</span>d, @starting<span style="color: #808080;">&#41;</span>;
	<span style="color: #0000FF;">SET</span> @command <span style="color: #808080;">=</span> <span style="color: #FF0000;">'date '</span> <span style="color: #808080;">+</span> @<span style="color: #0000FF;">date</span>;
	<span style="color: #0000FF;">EXEC</span> xp_cmdshell @command, no_output;
&nbsp;
	<span style="color: #008080;">-- SQL Server takes a while to pickup the date change</span>
	<span style="color: #008080;">-- Loop around until the day has changed before executing the proc</span>
	<span style="color: #0000FF;">WHILE</span><span style="color: #808080;">&#40;</span>@<span style="color: #0000FF;">day</span> <span style="color: #808080;">&lt;&gt;</span> <span style="color: #FF00FF;">DATEPART</span><span style="color: #808080;">&#40;</span>d, <span style="color: #FF00FF;">GETDATE</span><span style="color: #808080;">&#40;</span><span style="color: #808080;">&#41;</span><span style="color: #808080;">&#41;</span><span style="color: #808080;">&#41;</span>
	<span style="color: #0000FF;">BEGIN</span>
		<span style="color: #0000FF;">WAITFOR</span> DELAY <span style="color: #FF0000;">'00:00:01'</span>;
	<span style="color: #0000FF;">END</span>
&nbsp;
	<span style="color: #008080;">-- Call the procedure with the changed date</span>
	<span style="color: #0000FF;">EXEC</span> dbo.<span style="color: #202020;">usp_isItSaturday</span>;  
	<span style="color: #008080;">-- Increment date by 1 day</span>
	<span style="color: #0000FF;">SET</span> @starting <span style="color: #808080;">=</span> <span style="color: #FF00FF;">DATEADD</span><span style="color: #808080;">&#40;</span>d, <span style="color: #000;">1</span>, @starting<span style="color: #808080;">&#41;</span>;
&nbsp;
<span style="color: #0000FF;">END</span> 
&nbsp;
<span style="color: #008080;">-- Disable xp_cmdshell</span>
<span style="color: #0000FF;">EXEC</span> master.<span style="color: #202020;">dbo</span>.<span style="color: #AF0000;">sp_configure</span> <span style="color: #FF0000;">'xp_cmdshell'</span>, <span style="color: #000;">0</span>;
<span style="color: #0000FF;">RECONFIGURE</span>;</pre></td></tr></table></div>

<p>Here&#8217;s a sample of the output. You can see it has correctly identified the days that are Saturday.</p>
<p><a href="http://www.youdidwhatwithtsql.com/wp-content/uploads/2009/11/usp_isItSaturday.png"><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="usp_isItSaturday" border="0" alt="usp isItSaturday thumb Testing datetime dependent Stored Procedures" src="http://www.youdidwhatwithtsql.com/wp-content/uploads/2009/11/usp_isItSaturday_thumb.png" width="121" height="244" /></a></p>
<p><map name='google_ad_map_433_a45beff5d2e172f6'>
<area shape='rect' href='http://imageads.googleadservices.com/pagead/imgclick/433?pos=0' coords='1,2,367,28' />
<area shape='rect' href='http://services.google.com/feedback/abg' coords='384,10,453,23'/></map>
<img usemap='#google_ad_map_433_a45beff5d2e172f6' border='0' src='http://imageads.googleadservices.com/pagead/ads?format=468x30_aff_img&amp;client=&amp;channel=&amp;output=png&amp;cuid=433&amp;url=http%3A%2F%2Fwww.youdidwhatwithtsql.com%2Ftesting-datetime-dependent-stored-procedures%2F433' title="Testing datetime dependent Stored Procedures" alt=" Testing datetime dependent Stored Procedures" /></p><p>Post from: <a href="http://www.youdidwhatwithtsql.com">youdidwhatwithtsql.com</a><br/><br/><a href="http://www.youdidwhatwithtsql.com/testing-datetime-dependent-stored-procedures/433">Testing datetime dependent Stored Procedures</a></p>
<div class="none"><div class="g-plusone" data-href="http://www.youdidwhatwithtsql.com/testing-datetime-dependent-stored-procedures/433" size="standard" count="true"></div></div>]]></content:encoded>
			<wfw:commentRss>http://www.youdidwhatwithtsql.com/testing-datetime-dependent-stored-procedures/433/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Computed Columns in SQL Server</title>
		<link>http://www.youdidwhatwithtsql.com/computed-columns-in-sql-server/377</link>
		<comments>http://www.youdidwhatwithtsql.com/computed-columns-in-sql-server/377#comments</comments>
		<pubDate>Sat, 26 Sep 2009 19:33:32 +0000</pubDate>
		<dc:creator>Rhys</dc:creator>
				<category><![CDATA[T-SQL]]></category>
		<category><![CDATA[Computed Columns]]></category>
		<category><![CDATA[SQL Server 2008]]></category>
		<category><![CDATA[TSQL]]></category>

		<guid isPermaLink="false">http://www.youdidwhatwithtsql.com/computed-columns-in-sql-server/377</guid>
		<description><![CDATA[So exactly what is a computed column? MSDN has this to say A computed column is computed from an expression that can use other columns in the same table. The expression can be a noncomputed column name, constant, function, and any combination of these connected by one or more operators. The expression cannot be a [...]<p>Post from: <a href="http://www.youdidwhatwithtsql.com">youdidwhatwithtsql.com</a><br/><br/><a href="http://www.youdidwhatwithtsql.com/computed-columns-in-sql-server/377">Computed Columns in SQL Server</a></p>
]]></description>
			<content:encoded><![CDATA[<p>So exactly what is a computed column? <a href="http://msdn.microsoft.com/en-us/library/ms191250.aspx" target="_blank">MSDN</a> has this to say</p>
<blockquote><p>A computed column is computed from an expression that can use other columns in the same table. The expression can be a noncomputed column name, constant, function, and any combination of these connected by one or more operators. The expression cannot be a subquery.</p>
</blockquote>
<p>Essentially there are two types of computed columns; a virtual column where the data is not physically stored in the table, values are calculated each time it is referenced in a query. These cannot be indexed. By making use of the PERSISTED TSQL keyword we can force the database engine to physically store this data in the table. These can be indexed provided the computation definition is deterministic. For example, we wouldn’t be permitted to index columns containing a call to the <a href="http://msdn.microsoft.com/en-us/library/ms188383.aspx" target="_blank">GETDATE</a> function.</p>
<p>Some people consider virtual computed columns to be a <a href="http://forums.mysql.com/read.php?10,218549,218555#msg-218555" target="_blank">waste of time</a>. Sure, it’s easy enough to build something like monthPay * 12 AS YearlySalary into your queries but in my opinion they offer the following benefits.</p>
<ul>
<li>Enforce a particular calculation method in your organisation. </li>
<li>Should the calculation need to change, modify the computed column definition and not loads of queries, procedures and reports. (Anyone having to cope with the UK’s <a href="http://www.hmrc.gov.uk/pbr2008/measure1.htm" target="_blank">change in VAT</a> last year will appreciate this). </li>
</ul>
<p>I’ve put persisted computed columns to good use recently. Some data came in from a client in an unexpected format. The record key value was sometimes contained in a column that was basically a <a href="http://en.wikipedia.org/wiki/Hodge-podge" target="_blank">hodge-podge</a> of notes. I created a computed column that extracted this value which then allowed it to be indexed. </p>
<p>Here’s an brief example of what I did to achieve this.</p>
<p>The code here uses SQL Server 2008. Firstly I created a <a href="http://msdn.microsoft.com/en-us/library/ms186755.aspx" target="_blank">user-defined function</a> that would extract the required key value from a note field.</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p377code15'); return false;">View Code</a> TSQL</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p37715"><td class="code" id="p377code15"><pre class="tsql" style="font-family:monospace;"><span style="color: #008080;">-- This function will provide the computed column definition</span>
<span style="color: #0000FF;">CREATE</span> <span style="color: #0000FF;">FUNCTION</span> udf_extractPersonCode
<span style="color: #808080;">&#40;</span>
	@<span style="color: #0000FF;">input</span> <span style="color: #0000FF;">VARCHAR</span><span style="color: #808080;">&#40;</span><span style="color: #000;">100</span><span style="color: #808080;">&#41;</span>
<span style="color: #808080;">&#41;</span>
<span style="color: #0000FF;">RETURNS</span> <span style="color: #0000FF;">CHAR</span><span style="color: #808080;">&#40;</span><span style="color: #000;">7</span><span style="color: #808080;">&#41;</span>
<span style="color: #0000FF;">WITH</span> SCHEMAB<span style="color: #808080;">IN</span>D<span style="color: #808080;">IN</span>G
<span style="color: #0000FF;">AS</span>
<span style="color: #0000FF;">BEGIN</span>
&nbsp;
	<span style="color: #0000FF;">DECLARE</span> @extractedPersonCode <span style="color: #0000FF;">CHAR</span><span style="color: #808080;">&#40;</span><span style="color: #000;">7</span><span style="color: #808080;">&#41;</span> <span style="color: #808080;">=</span> <span style="color: #808080;">NULL</span>;
&nbsp;
	<span style="color: #0000FF;">IF</span><span style="color: #808080;">&#40;</span><span style="color: #FF00FF;">PATINDEX</span><span style="color: #808080;">&#40;</span><span style="color: #FF0000;">'%[A-Z][0-9][0-9][0-9][0-9][0-9][0-9]%'</span>, @<span style="color: #0000FF;">input</span><span style="color: #808080;">&#41;</span> <span style="color: #808080;">&gt;</span> <span style="color: #000;">0</span><span style="color: #808080;">&#41;</span>
	<span style="color: #0000FF;">BEGIN</span>
		<span style="color: #0000FF;">SET</span> @extractedPersonCode <span style="color: #808080;">=</span> <span style="color: #FF00FF;">SUBSTRING</span><span style="color: #808080;">&#40;</span>@<span style="color: #0000FF;">input</span>, <span style="color: #FF00FF;">PATINDEX</span><span style="color: #808080;">&#40;</span><span style="color: #FF0000;">'%[A-Z][0-9][0-9][0-9][0-9][0-9][0-9]%'</span>, @<span style="color: #0000FF;">input</span><span style="color: #808080;">&#41;</span>, <span style="color: #000;">7</span><span style="color: #808080;">&#41;</span>;
	<span style="color: #0000FF;">END</span>
&nbsp;
	<span style="color: #0000FF;">RETURN</span> @extractedPersonCode;
&nbsp;
<span style="color: #0000FF;">END</span>
GO</pre></td></tr></table></div>

<p>The WITH SCHEMABINDING is needed in the function definition or the following error will occur when attempting to create the function.</p>
<pre>Msg 4936, Level 16, State 1, Line 1
Computed column 'ExtractedPersonCode' in table 'ComputedColTable' cannot be persisted because the column is non-deterministic.</pre>
<p>Create this test table in the same database as the function. Note the definition of the computed column <strong>ExtractedPersonCode</strong>.</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p377code16'); return false;">View Code</a> TSQL</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p37716"><td class="code" id="p377code16"><pre class="tsql" style="font-family:monospace;"><span style="color: #0000FF;">CREATE</span> <span style="color: #0000FF;">TABLE</span> dbo.<span style="color: #202020;">ComputedColTable</span>
<span style="color: #808080;">&#40;</span>
	Id <span style="color: #0000FF;">INTEGER</span> <span style="color: #0000FF;">IDENTITY</span><span style="color: #808080;">&#40;</span><span style="color: #000;">1</span>, <span style="color: #000;">1</span><span style="color: #808080;">&#41;</span> <span style="color: #808080;">NOT</span> <span style="color: #808080;">NULL</span> <span style="color: #0000FF;">PRIMARY</span> <span style="color: #0000FF;">KEY</span> <span style="color: #0000FF;">CLUSTERED</span>,
	FirstName <span style="color: #0000FF;">VARCHAR</span><span style="color: #808080;">&#40;</span><span style="color: #000;">30</span><span style="color: #808080;">&#41;</span> <span style="color: #808080;">NOT</span> <span style="color: #808080;">NULL</span>,
	LastName <span style="color: #0000FF;">VARCHAR</span><span style="color: #808080;">&#40;</span><span style="color: #000;">30</span><span style="color: #808080;">&#41;</span> <span style="color: #808080;">NOT</span> <span style="color: #808080;">NULL</span>,
	PersonCode <span style="color: #0000FF;">CHAR</span><span style="color: #808080;">&#40;</span><span style="color: #000;">7</span><span style="color: #808080;">&#41;</span> <span style="color: #808080;">NULL</span>,
	Notes <span style="color: #0000FF;">VARCHAR</span><span style="color: #808080;">&#40;</span><span style="color: #000;">100</span><span style="color: #808080;">&#41;</span> <span style="color: #808080;">NULL</span>,
	ExtractedPersonCode <span style="color: #0000FF;">AS</span> dbo.<span style="color: #202020;">udf_extractPersonCode</span><span style="color: #808080;">&#40;</span>Notes<span style="color: #808080;">&#41;</span> PERSISTED
<span style="color: #808080;">&#41;</span>;</pre></td></tr></table></div>

<p>Now insert some test data.</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p377code17'); return false;">View Code</a> TSQL</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p37717"><td class="code" id="p377code17"><pre class="tsql" style="font-family:monospace;"><span style="color: #008080;">-- Insert some sample data into our table</span>
<span style="color: #0000FF;">INSERT</span> <span style="color: #0000FF;">INTO</span> dbo.<span style="color: #202020;">ComputedColTable</span>
<span style="color: #808080;">&#40;</span>
	FirstName,
	LastName,
	PersonCode,
	Notes
<span style="color: #808080;">&#41;</span>
<span style="color: #0000FF;">VALUES</span>
<span style="color: #808080;">&#40;</span>
	<span style="color: #FF0000;">'Rhys'</span>,
	<span style="color: #FF0000;">'Campbell'</span>,
	<span style="color: #FF0000;">'C123456'</span>, <span style="color: #008080;">-- Correctly entered PersonCode</span>
	<span style="color: #808080;">NULL</span>
<span style="color: #808080;">&#41;</span>,
<span style="color: #808080;">&#40;</span>
	<span style="color: #FF0000;">'John'</span>,
	<span style="color: #FF0000;">'Smith'</span>,
	<span style="color: #808080;">NULL</span>, <span style="color: #008080;">-- No Person Code here</span>
	<span style="color: #FF0000;">'Person code = C654321 New Customer'</span> <span style="color: #008080;">-- PersonCode put in notes</span>
<span style="color: #808080;">&#41;</span>,
<span style="color: #808080;">&#40;</span>
	<span style="color: #FF0000;">'Joe'</span>,
	<span style="color: #FF0000;">'Bloggs'</span>,
	<span style="color: #808080;">NULL</span>, <span style="color: #008080;">-- No Person Code here</span>
	<span style="color: #FF0000;">'Visited London store C654320 customer code.'</span> <span style="color: #008080;">-- PersonCode put in notes</span>
<span style="color: #808080;">&#41;</span>;</pre></td></tr></table></div>

<p>Now lets view the data.</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p377code18'); return false;">View Code</a> TSQL</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p37718"><td class="code" id="p377code18"><pre class="tsql" style="font-family:monospace;"><span style="color: #008080;">-- Select data</span>
<span style="color: #0000FF;">SELECT</span> <span style="color: #808080;">*</span>
<span style="color: #0000FF;">FROM</span> dbo.<span style="color: #202020;">ComputedColTable</span></pre></td></tr></table></div>

<p><a href="http://www.youdidwhatwithtsql.com/wp-content/uploads/2009/09/computed_column_sql_server.png"><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="computed_column_sql_server" border="0" alt="computed column sql server thumb Computed Columns in SQL Server" src="http://www.youdidwhatwithtsql.com/wp-content/uploads/2009/09/computed_column_sql_server_thumb.png" width="644" height="111" /></a> </p>
<p>Now we have cleaner data without any manual intervention needed.</p>
<p><map name='google_ad_map_377_a45beff5d2e172f6'>
<area shape='rect' href='http://imageads.googleadservices.com/pagead/imgclick/377?pos=0' coords='1,2,367,28' />
<area shape='rect' href='http://services.google.com/feedback/abg' coords='384,10,453,23'/></map>
<img usemap='#google_ad_map_377_a45beff5d2e172f6' border='0' src='http://imageads.googleadservices.com/pagead/ads?format=468x30_aff_img&amp;client=&amp;channel=&amp;output=png&amp;cuid=377&amp;url=http%3A%2F%2Fwww.youdidwhatwithtsql.com%2Fcomputed-columns-in-sql-server%2F377' title="Computed Columns in SQL Server" alt=" Computed Columns in SQL Server" /></p><p>Post from: <a href="http://www.youdidwhatwithtsql.com">youdidwhatwithtsql.com</a><br/><br/><a href="http://www.youdidwhatwithtsql.com/computed-columns-in-sql-server/377">Computed Columns in SQL Server</a></p>
<div class="none"><div class="g-plusone" data-href="http://www.youdidwhatwithtsql.com/computed-columns-in-sql-server/377" size="standard" count="true"></div></div>]]></content:encoded>
			<wfw:commentRss>http://www.youdidwhatwithtsql.com/computed-columns-in-sql-server/377/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>

