<?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; Bank Holidays</title>
	<atom:link href="http://www.youdidwhatwithtsql.com/tag/bank-holidays/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>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>
	</channel>
</rss>

