<?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>Richard Douglas - SQL Server Professional</title>
	<atom:link href="http://sql.richarddouglas.co.uk/feed" rel="self" type="application/rss+xml" />
	<link>http://sql.richarddouglas.co.uk</link>
	<description>Real world SQL advice and tips</description>
	<lastBuildDate>Mon, 08 Mar 2010 14:09:57 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Installing SQL Server with Slipstream</title>
		<link>http://sql.richarddouglas.co.uk/archive/2010/03/installing-sql-server-with-slipstream.html</link>
		<comments>http://sql.richarddouglas.co.uk/archive/2010/03/installing-sql-server-with-slipstream.html#comments</comments>
		<pubDate>Mon, 08 Mar 2010 14:09:57 +0000</pubDate>
		<dc:creator>Richard Douglas</dc:creator>
				<category><![CDATA[Installation]]></category>
		<category><![CDATA[SQL 2008]]></category>

		<guid isPermaLink="false">http://sql.richarddouglas.co.uk/?p=306</guid>
		<description><![CDATA[<p>Many thanks to Christian Bolton for telling me about &#8220;Slipstream&#8221; and how it can streamline your installation process.</p>
<p>Wikipedia defines slipstreaming as:</p>
<p>In computer jargon, to slipstream updates, patches or service packs means to integrate them into the installation files of their original software, so that the resulting files will allow a direct installation of the updated software.</p>
<p>If [...]]]></description>
			<content:encoded><![CDATA[<p>Many thanks to <a href="http://sqlblogcasts.com/blogs/christian/">Christian Bolton</a> for telling me about &#8220;Slipstream&#8221; and how it can streamline your installation process.</p>
<p>Wikipedia defines slipstreaming as:</p>
<blockquote><p>In computer <a title="Jargon" href="/wiki/Jargon">jargon</a>, <strong>to slipstream</strong> updates, <a title="Patch (computing)" href="/wiki/Patch_(computing)">patches</a> or <a title="Service pack" href="/wiki/Service_pack">service packs</a> means to integrate them into the <a title="Installation (computer programs)" href="/wiki/Installation_(computer_programs)">installation</a> files of their original software, so that the resulting files will allow a direct installation of the updated software.</p>
<p>If not directly supported by the software vendor, slipstreaming can be technically possible, depending on the updates, the structure and type of the program to be slipstreamed and of its installer, if any.</p></blockquote>
<p>Slipstreaming is new functionality to SQL Server 2008 which allows you to install service packs and cumulative updates whilst installing the base version of SQL.</p>
<p>I tried it out this morning and it&#8217;s a pretty simple process to follow, the good thing about it is you can store this on the network and use it as a base installation. The guide I followed was:<a href="http://blogs.msdn.com/petersad/archive/2009/02/25/sql-server-2008-creating-a-merged-slisptream-drop.aspx">http://blogs.msdn.com/petersad/archive/2009/02/25/sql-server-2008-creating-a-merged-slisptream-drop.aspx</a> which worked a treat.</p>
<p>The full Microsoft KB article is available here: <a href="http://support.microsoft.com/kb/955392">http://support.microsoft.com/kb/955392</a></p>
<p>Unless you have the very latest installation disks this is definitely someing to squirrel away for your next installation.</p>
]]></content:encoded>
			<wfw:commentRss>http://sql.richarddouglas.co.uk/archive/2010/03/installing-sql-server-with-slipstream.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>New Arrival</title>
		<link>http://sql.richarddouglas.co.uk/archive/2010/03/new-arrival.html</link>
		<comments>http://sql.richarddouglas.co.uk/archive/2010/03/new-arrival.html#comments</comments>
		<pubDate>Sat, 06 Mar 2010 22:18:01 +0000</pubDate>
		<dc:creator>Richard Douglas</dc:creator>
				<category><![CDATA[Personal]]></category>

		<guid isPermaLink="false">http://sql.richarddouglas.co.uk/?p=301</guid>
		<description><![CDATA[<p>Things have been a bit hectic recently and unfortunately have not been able to post much, there has been a good reason for the silence. In February this year my wife and I were blessed with another son &#8220;Harry&#8221;, once everything has settled down into a routine normal blogging service will resume.</p>
]]></description>
			<content:encoded><![CDATA[<p>Things have been a bit hectic recently and unfortunately have not been able to post much, there has been a good reason for the silence. In February this year my wife and I were blessed with another son &#8220;Harry&#8221;, once everything has settled down into a routine normal blogging service will resume.</p>
]]></content:encoded>
			<wfw:commentRss>http://sql.richarddouglas.co.uk/archive/2010/03/new-arrival.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Custom plural notifications in SSIS</title>
		<link>http://sql.richarddouglas.co.uk/archive/2010/03/custom-plural-notifications-in-ssis.html</link>
		<comments>http://sql.richarddouglas.co.uk/archive/2010/03/custom-plural-notifications-in-ssis.html#comments</comments>
		<pubDate>Wed, 03 Mar 2010 14:25:06 +0000</pubDate>
		<dc:creator>Richard Douglas</dc:creator>
				<category><![CDATA[SSIS]]></category>
		<category><![CDATA[expressions]]></category>

		<guid isPermaLink="false">http://sql.richarddouglas.co.uk/?p=262</guid>
		<description><![CDATA[<p>Adding notification messages in SSIS is really quite easy once you understand how you can use expressions, one of my pet hates is receiving process notification emails that contain things like &#34 file(s) processed&#34 or &#34 record(s) processed&#34.</p>
<p>So, now we have a scenario with a disgruntled user how do we create a more professional looking [...]]]></description>
			<content:encoded><![CDATA[<p>Adding notification messages in SSIS is really quite easy once you understand how you can use expressions, one of my pet hates is receiving process notification emails that contain things like &#34 file(s) processed&#34 or &#34 record(s) processed&#34.</p>
<p>So, now we have a scenario with a disgruntled user how do we create a more professional looking solution? Remember that your boss and maybe even your bosses boss will probably see these emails at some point, so you should make it as perfect as possible.</p>
<p>Not everyone will have an SMTP server available to test the notification especially if reading from home, not to worry in this post I <span> </span>will <span> </span>use some variables to simulate the object properties instead.</p>
<p>Normally to write a custom mail notification one would create an expression on the &#34<span>MessageSource</span>&#34 property of the &#34Send Mail Task&#34 for this example I am simply going to create the variable @[User::<span>MessageSource</span>] as a String and evaluate it as an expression. If you have not done this before then click on the variable name in the variables window to select it, then in the properties window change the value of &#34<span>EvaluateAsExpression</span>&#34 to True.</p>
<p>Next we are going to create an Int32 variable called &#34<span>RowCount</span>&#34, normally I would populate this variable using a &#8220;Row count&#8221; task within a Data Transformation Task, but for simplicity we will just create the variable and set it to 2.</p>
<p>The third and final variable in the puzzle is the variable &#34Plural&#34, again this is going to be evaluated as an expression. We can then set the value of @[User::Plural] as the following expression:</p>
<p>@[User::<span>RowCount</span>] == 1<span> </span>? &#34&#34 : &#34s&#34</p>
<p>If you’re not familiar with SSIS expressions then in T-SQL it would look something like the following:</p>
<p><span style="font-family: 'Courier New'; color: blue; font-size: 10pt;">IF </span><span style="font-family: 'Courier New'; font-size: 10pt;">@RowCount <span style="color: gray;">=</span> 1</span></p>
<p><span style="font-family: 'Courier New'; color: blue; font-size: 10pt;">BEGIN</span></p>
<p><span style="font-family: 'Courier New'; font-size: 10pt;"><span style="color: blue;">SET</span> @Plural <span style="color: gray;">=</span> <span style="color: red;">&#34&#34</span></span></p>
<p><span style="font-family: 'Courier New'; color: blue; font-size: 10pt;">END</span><span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: blue;">ELSE</span></span></p>
<p><span style="font-family: 'Courier New'; color: blue; font-size: 10pt;">BEGIN</span></p>
<p><span style="font-family: 'Courier New'; font-size: 10pt;"><span style="color: blue;">SET</span> @Plural <span style="color: gray;">=</span> <span style="color: red;">&#39s&#39</span></span></p>
<p><span style="font-family: 'Courier New'; color: blue; font-size: 10pt;">END</span></p>
<p>Now we have set our Plural variable we can now go back and create the expression for the <span>MessageSource</span> variable as the following:</p>
<p>&#34The successful process imported &#34 +<span> </span>(DT_STR, 10, 1252) @[User::<span>RowCount</span>] + &#34 record&#34 +<span> </span>@[User::Plural] + &#34.\n\<span>nRegards</span>,\<span>nYour</span> Helpful DBA&#8221;</p>
<p>If you click on the &#34Evaluate Expression&#34 box this will return:</p>
<p>The successful process imported 2 records.</p>
<p>Regards,</p>
<p>Your Helpful DBA</p>
<p>&#13;&#10;<br />
&#13;&#10;<br />
To test that the plural aspect works change the value of the variable <span>RowCount</span> to 1 and evaluate <span>MessageSource</span> again, this time the results will be:</p>
<p>The successful process imported 1 record.</p>
<p>Regards,</p>
<p>Your Helpful DBA</p>
<p>&#13;&#10;<br />
&#13;&#10;<br />
There we have it, if you haven’t used variables as expressions before then it&#8217;s a very useful lesson as expressions are the building blocks for practically everything in SSIS, once you&#8217;ve mastered this simple concept you will find that everything becomes much easier.</p>
]]></content:encoded>
			<wfw:commentRss>http://sql.richarddouglas.co.uk/archive/2010/03/custom-plural-notifications-in-ssis.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>SQL Bits VI</title>
		<link>http://sql.richarddouglas.co.uk/archive/2010/02/sql-bits-vi.html</link>
		<comments>http://sql.richarddouglas.co.uk/archive/2010/02/sql-bits-vi.html#comments</comments>
		<pubDate>Fri, 12 Feb 2010 17:19:48 +0000</pubDate>
		<dc:creator>Richard Douglas</dc:creator>
				<category><![CDATA[Events]]></category>
		<category><![CDATA[SQLBits]]></category>

		<guid isPermaLink="false">http://sql.richarddouglas.co.uk/?p=282</guid>
		<description><![CDATA[<p>Simon Sabin announced in his blog earlier today here details about SQLBits VI.</p>
<p>The event is on Friday 16th April at the Church House Conference Centre in Westminster, London and will be free!</p>
<p>For more information go to the SQLBits website.</p>
]]></description>
			<content:encoded><![CDATA[<p>Simon Sabin announced in his blog earlier today <a href="http://sqlblogcasts.com/blogs/simons/archive/2010/02/12/SQLBits-VI---Date-and-Location-announced.aspx">here</a> details about SQLBits VI.</p>
<p>The event is on Friday 16th April at the Church House Conference Centre in Westminster, London and will be free!</p>
<p>For more information go to the <a href="http://www.sqlbits.com/default.aspx">SQLBits</a> website.</p>
]]></content:encoded>
			<wfw:commentRss>http://sql.richarddouglas.co.uk/archive/2010/02/sql-bits-vi.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>New Year, New Opportunities</title>
		<link>http://sql.richarddouglas.co.uk/archive/2010/01/new-year-new-opportunities.html</link>
		<comments>http://sql.richarddouglas.co.uk/archive/2010/01/new-year-new-opportunities.html#comments</comments>
		<pubDate>Thu, 14 Jan 2010 23:18:24 +0000</pubDate>
		<dc:creator>Richard Douglas</dc:creator>
				<category><![CDATA[Ad-hoc]]></category>
		<category><![CDATA[Personal]]></category>

		<guid isPermaLink="false">http://sql.richarddouglas.co.uk/?p=259</guid>
		<description><![CDATA[<p>Like many people I have taken the steps of acquiring a new job during the New Year merry go round. After a brief search I have been offered and accepted a position as a SQL DBA at a well known UK retailer.</p>
<p>There have been lots of posts on forums and mailing lists asking for hints and [...]]]></description>
			<content:encoded><![CDATA[<p>Like many people I have taken the steps of acquiring a new job during the New Year merry go round. After a brief search I have been offered and accepted a position as a SQL DBA at a well known UK retailer.</p>
<p>There have been lots of posts on forums and mailing lists asking for hints and tips on interviews and sample questions, whilst I think it is unfair to list exact questions I would expect anyone going for a SQL job to have a thorough grounding in the following areas at the very minimum:</p>
<ul>
<li>The structure of a database.</li>
<li>Backing up a database, recovery models and backup types.</li>
<li>An understanding of the different indexes available.</li>
<li>Detail the steps of a maintenance plan.</li>
<li>Thorough understanding of T-SQL querying commands.</li>
</ul>
<p>Other roles such as a BI Analyst or SQL Developer may be more specialised and so could include the following:</p>
<ul>
<li>SSIS/DTS</li>
<li>SSAS</li>
<li>SSRS</li>
</ul>
<p>If you are looking for a new job at the moment either through choice or as a victim of the recession then it would be worth having professional help with your CV. Since handing in my notice I have seen first hand at how people look at resume&#8217;s whilst managers have been looking for my replacement and from the comments I have heard basic mistakes will put potential employers off. There are a number of companies offering free advice just a click away with your favourite search engine.</p>
]]></content:encoded>
			<wfw:commentRss>http://sql.richarddouglas.co.uk/archive/2010/01/new-year-new-opportunities.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Happy New Year 2010</title>
		<link>http://sql.richarddouglas.co.uk/archive/2010/01/happy-new-year-2010.html</link>
		<comments>http://sql.richarddouglas.co.uk/archive/2010/01/happy-new-year-2010.html#comments</comments>
		<pubDate>Fri, 01 Jan 2010 00:00:50 +0000</pubDate>
		<dc:creator>Richard Douglas</dc:creator>
				<category><![CDATA[Ad-hoc]]></category>
		<category><![CDATA[seasonal]]></category>

		<guid isPermaLink="false">http://sql.richarddouglas.co.uk/?p=253</guid>
		<description><![CDATA[<p>I&#8217;d like to wish you all a happy new year in which we can all look forward to the release on SQL 2008 R2 and Powerpoint!</p>
]]></description>
			<content:encoded><![CDATA[<p>I&#8217;d like to wish you all a happy new year in which we can all look forward to the release on SQL 2008 R2 and Powerpoint!</p>
]]></content:encoded>
			<wfw:commentRss>http://sql.richarddouglas.co.uk/archive/2010/01/happy-new-year-2010.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Merry Christmas 2009</title>
		<link>http://sql.richarddouglas.co.uk/archive/2009/12/merry-christmas-2009.html</link>
		<comments>http://sql.richarddouglas.co.uk/archive/2009/12/merry-christmas-2009.html#comments</comments>
		<pubDate>Fri, 25 Dec 2009 00:00:45 +0000</pubDate>
		<dc:creator>Richard Douglas</dc:creator>
				<category><![CDATA[Ad-hoc]]></category>
		<category><![CDATA[seasonal]]></category>

		<guid isPermaLink="false">http://sql.richarddouglas.co.uk/?p=247</guid>
		<description><![CDATA[<p>I&#8217;d like to take this opportunity to wish you and your families a very Merry Christmas!</p>
]]></description>
			<content:encoded><![CDATA[<p>I&#8217;d like to take this opportunity to wish you and your families a very Merry Christmas!</p>
]]></content:encoded>
			<wfw:commentRss>http://sql.richarddouglas.co.uk/archive/2009/12/merry-christmas-2009.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Installing Anti Virus on a SQL Server</title>
		<link>http://sql.richarddouglas.co.uk/archive/2009/12/installing-anti-virus-on-a-sql-server.html</link>
		<comments>http://sql.richarddouglas.co.uk/archive/2009/12/installing-anti-virus-on-a-sql-server.html#comments</comments>
		<pubDate>Wed, 23 Dec 2009 23:14:22 +0000</pubDate>
		<dc:creator>Richard Douglas</dc:creator>
				<category><![CDATA[Server Admin]]></category>
		<category><![CDATA[Anti Virus]]></category>
		<category><![CDATA[SQL 2000]]></category>
		<category><![CDATA[SQL 2005]]></category>
		<category><![CDATA[SQL 2008]]></category>

		<guid isPermaLink="false">http://sql.richarddouglas.co.uk/?p=244</guid>
		<description><![CDATA[<p>It&#8217;s been quite a while since I last posted anything on this site, there&#8217;s been a lot of change behind the scenes and have a number of entries to post based on things that have happened in the last few weeks.</p>
<p>Earlier this week I was asked by one of our infrastructure guys when would be [...]]]></description>
			<content:encoded><![CDATA[<p>It&#8217;s been quite a while since I last posted anything on this site, there&#8217;s been a lot of change behind the scenes and have a number of entries to post based on things that have happened in the last few weeks.</p>
<p>Earlier this week I was asked by one of our infrastructure guys when would be a good time to take down one of the servers and push out some new anti virus software using SMS (Server Management System) we arranged a suitable time where the no users would be affected but the real key issue as a DBA is to make sure that the anti virus software does not adversely affect performance.</p>
<p>There are differing schools of thought on whether anti virus should be applied or not because of performance reasons. If you are thinking about adding an AV solution to your SQL Servers or have already done so then please check the Microsoft KB article <a href="http://support.microsoft.com/kb/309422">http://support.microsoft.com/kb/309422</a> to see what Microsoft recommends on this contentious issue.</p>
]]></content:encoded>
			<wfw:commentRss>http://sql.richarddouglas.co.uk/archive/2009/12/installing-anti-virus-on-a-sql-server.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Leeds SQL User Group</title>
		<link>http://sql.richarddouglas.co.uk/archive/2009/12/leeds-sql-user-group.html</link>
		<comments>http://sql.richarddouglas.co.uk/archive/2009/12/leeds-sql-user-group.html#comments</comments>
		<pubDate>Wed, 09 Dec 2009 08:00:15 +0000</pubDate>
		<dc:creator>Richard Douglas</dc:creator>
				<category><![CDATA[Events]]></category>

		<guid isPermaLink="false">http://sql.richarddouglas.co.uk/?p=185</guid>
		<description><![CDATA[<p>Join Anthony Brown and Martin Bell tomorrow for an evening on Service Broker and an introduction to SQL&#8217;s version of PowerShell. There will be a prize draw for a copy of Windows 7 Ultimate during the evening as well as other goodies.</p>
<p>You will need to register for this event, to do so click on the [...]]]></description>
			<content:encoded><![CDATA[<p>Join <a href="http://sqlblogcasts.com/blogs/antxxxx/Default.aspx" target="_blank">Anthony Brown</a> and <a href="http://sqlblogcasts.com/blogs/martinbell/" target="_blank">Martin Bell</a> tomorrow for an evening on Service Broker and an introduction to SQL&#8217;s version of PowerShell. There will be a prize draw for a copy of Windows 7 Ultimate during the evening as well as other goodies.</p>
<p>You will need to register for this event, to do so click on the following <a href="http://sqlserverfaq.com/events/207/An-evening-of-Service-Broker-and-Powershell.aspx" target="_blank">link</a>.</p>
<div id="canvas_PDCd" style="width:400px; height:400px" class="google-map-sc-canvas"></div><script type="text/javascript">
var map_canvas_PDCd;
var map_points_canvas_PDCd =  new Array();
map_points_canvas_PDCd[0] = {'point':{'lat':"53.7980479",'long':"-1.5479393"},'info':"<div class='gm_info_cont'><p class='gm_info_title'><a class='title' href='http://sql.richarddouglas.co.uk/?p=185'>Leeds SQL User Group</a></p><p class='gm_info_address'>Russell St, Leeds LS1 5, UK</p><table border='0' cellspacing='0' cellpadding='5' height='80'><tr><td valign='top' align='left'><a href='http://sql.richarddouglas.co.uk/?p=185'><img src='' class='gm_info_img' /></a></td><td valign='top' align='left'>Join Anthony Brown and Martin Bell tomorrow for an evening ...<p><a href='http://sql.richarddouglas.co.uk/?p=185'>more »</a></p></td></tr></table></div>"};
addLoadEvent(function(){
map_canvas_PDCd = new gmshc_render("canvas_PDCd",map_points_canvas_PDCd, 3);
});
addEvent(window,'unload',GUnload,false);
</script>
<div class='map_links'><ul><li><a href='#' onclick='map_canvas_PDCd.findPoint(0); return false'>Leeds SQL User Group</a></li></ul></div
]]></content:encoded>
			<wfw:commentRss>http://sql.richarddouglas.co.uk/archive/2009/12/leeds-sql-user-group.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Finding Files: Part 2 ActiveX</title>
		<link>http://sql.richarddouglas.co.uk/archive/2009/11/finding-files-part-2-activex.html</link>
		<comments>http://sql.richarddouglas.co.uk/archive/2009/11/finding-files-part-2-activex.html#comments</comments>
		<pubDate>Mon, 30 Nov 2009 23:17:44 +0000</pubDate>
		<dc:creator>Richard Douglas</dc:creator>
				<category><![CDATA[ActiveX]]></category>
		<category><![CDATA[linkedIn]]></category>

		<guid isPermaLink="false">http://sql.richarddouglas.co.uk/?p=206</guid>
		<description><![CDATA[The second part of this series on finding files in SQL Server introduces the [...]]]></description>
			<content:encoded><![CDATA[<p>This is the second entry in the series on how you can check for the existence of files in SQL Server, in part 1 <a href="http://sql.richarddouglas.co.uk/archive/2009/10/finding-files-part-1-t-sql.html" target="_blank">Finding files in T-SQL</a> we covered how the undocumented sp xp_FileExists could be used.</p>
<p>In this entry I will be introducing an overview of the FileSystemObject which we will be using primarily to check for the existence of files.</p>
<p>In the first example we shall create a job called &#8220;TEST &#8211; Find Files&#8221; with 4 steps which will do the following:</p>
<ol>
<li>Create a file C:\Test.txt<br />
In this step we use CreateTextFile method to create our test file.</li>
<li>Check for the existence of the file C:\ThisIsntWhatICreated.txt<br />
In this step we use the FileExists method to check for our test file.</li>
<li>Delete the file C:\Test.txt<br />
In this step we use the DeleteFile method to delete our test file.</li>
<li>Create a Failed step for notification purposes.<br />
This step is just to show that another step can be run if the file does not exist.</li>
</ol>
<p>The code for this job can be found below:</p>
<div id="codeSnippetWrapper" style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; width: 96.8%; font-family: 'Courier New', courier, monospace; direction: ltr; height: 287px; max-height: 200px; font-size: 8pt; overflow: auto; cursor: text; border: silver 1px solid; padding: 4px;">
<div id="codeSnippet" style="text-align: left; line-height: 12pt; background-color: #f4f4f4; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">
<pre style="text-align: left; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #008000">-- Script generated by Richard Douglas </span></pre>
<p><!--CRLF--></p>
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #0000ff">BEGIN</span> <span style="color: #0000ff">TRANSACTION</span></pre>
<p><!--CRLF--></p>
<pre style="text-align: left; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">  <span style="color: #0000ff">DECLARE</span> @JobID <span style="color: #0000ff">BINARY</span>(16)</pre>
<p><!--CRLF--></p>
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">  <span style="color: #0000ff">DECLARE</span> @ReturnCode <span style="color: #0000ff">INT</span></pre>
<p><!--CRLF--></p>
<pre style="text-align: left; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">  <span style="color: #0000ff">SELECT</span> @ReturnCode = 0</pre>
<p><!--CRLF--></p>
<p><!--CRLF--></p>
<pre style="text-align: left; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #0000ff">IF</span> (<span style="color: #0000ff">SELECT</span> <span style="color: #0000ff">COUNT</span>(*) <span style="color: #0000ff">FROM</span> msdb.dbo.syscategories <span style="color: #0000ff">WHERE</span> name = N<span style="color: #006080">'[Test Job]'</span>) &lt; 1</pre>
<p><!--CRLF--></p>
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">  <span style="color: #0000ff">EXECUTE</span> msdb.dbo.sp_add_category @name = N<span style="color: #006080">'[Test Job]'</span></pre>
<p><!--CRLF--></p>
<p><!--CRLF--></p>
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">  <span style="color: #008000">-- Delete the job with the same name (if it exists)</span></pre>
<p><!--CRLF--></p>
<pre style="text-align: left; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">  <span style="color: #0000ff">SELECT</span> @JobID = job_id</pre>
<p><!--CRLF--></p>
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">  <span style="color: #0000ff">FROM</span>   msdb.dbo.sysjobs</pre>
<p><!--CRLF--></p>
<pre style="text-align: left; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">  <span style="color: #0000ff">WHERE</span> (name = N<span style="color: #006080">'TEST - Find File'</span>)</pre>
<p><!--CRLF--></p>
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">  <span style="color: #0000ff">IF</span> (@JobID <span style="color: #0000ff">IS</span> <span style="color: #0000ff">NOT</span> <span style="color: #0000ff">NULL</span>)</pre>
<p><!--CRLF--></p>
<pre style="text-align: left; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">  <span style="color: #0000ff">BEGIN</span></pre>
<p><!--CRLF--></p>
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">  <span style="color: #008000">-- Check if the job is a multi-server job  </span></pre>
<p><!--CRLF--></p>
<pre style="text-align: left; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">  <span style="color: #0000ff">IF</span> (<span style="color: #0000ff">EXISTS</span> (<span style="color: #0000ff">SELECT</span>  *</pre>
<p><!--CRLF--></p>
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">              <span style="color: #0000ff">FROM</span>    msdb.dbo.sysjobservers</pre>
<p><!--CRLF--></p>
<pre style="text-align: left; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">              <span style="color: #0000ff">WHERE</span>   (job_id = @JobID) <span style="color: #0000ff">AND</span> (server_id &lt;&gt; 0)))</pre>
<p><!--CRLF--></p>
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">  <span style="color: #0000ff">BEGIN</span></pre>
<p><!--CRLF--></p>
<pre style="text-align: left; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">    <span style="color: #008000">-- There is, so abort the script </span></pre>
<p><!--CRLF--></p>
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">    <span style="color: #0000ff">RAISERROR</span> (N<span style="color: #006080">'Unable to import job '</span><span style="color: #006080">'TEST - Find File'</span><span style="color: #006080">' since there is already a multi-server job with this name.'</span>, 16, 1)</pre>
<p><!--CRLF--></p>
<pre style="text-align: left; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">    <span style="color: #0000ff">GOTO</span> QuitWithRollback</pre>
<p><!--CRLF--></p>
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">  <span style="color: #0000ff">END</span></pre>
<p><!--CRLF--></p>
<pre style="text-align: left; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">  <span style="color: #0000ff">ELSE</span></pre>
<p><!--CRLF--></p>
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">    <span style="color: #008000">-- Delete the [local] job </span></pre>
<p><!--CRLF--></p>
<pre style="text-align: left; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">    <span style="color: #0000ff">EXECUTE</span> msdb.dbo.sp_delete_job @job_name = N<span style="color: #006080">'TEST - Find File'</span></pre>
<p><!--CRLF--></p>
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">    <span style="color: #0000ff">SELECT</span> @JobID = <span style="color: #0000ff">NULL</span></pre>
<p><!--CRLF--></p>
<pre style="text-align: left; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">  <span style="color: #0000ff">END</span></pre>
<p><!--CRLF--></p>
<p><!--CRLF--></p>
<pre style="text-align: left; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #0000ff">BEGIN</span></pre>
<p><!--CRLF--></p>
<p><!--CRLF--></p>
<pre style="text-align: left; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">  <span style="color: #008000">-- Add the job</span></pre>
<p><!--CRLF--></p>
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">  <span style="color: #0000ff">EXECUTE</span> @ReturnCode = msdb.dbo.sp_add_job @job_id = @JobID <span style="color: #0000ff">OUTPUT</span> , @job_name = N<span style="color: #006080">'TEST - Find File'</span>, @owner_login_name = suser_sname(), @description = N<span style="color: #006080">'No description available.'</span>, @category_name = N<span style="color: #006080">'[Test Job]'</span>, @enabled = 1, @notify_level_email = 0, @notify_level_page = 0, @notify_level_netsend = 0, @notify_level_eventlog = 2, @delete_level= 0</pre>
<p><!--CRLF--></p>
<pre style="text-align: left; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">  <span style="color: #0000ff">IF</span> (@@ERROR &lt;&gt; 0 <span style="color: #0000ff">OR</span> @ReturnCode &lt;&gt; 0) <span style="color: #0000ff">GOTO</span> QuitWithRollback</pre>
<p><!--CRLF--></p>
<p><!--CRLF--></p>
<pre style="text-align: left; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">  <span style="color: #008000">-- Add the job steps</span></pre>
<p><!--CRLF--></p>
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">  <span style="color: #0000ff">EXECUTE</span> @ReturnCode = msdb.dbo.sp_add_jobstep @job_id = @JobID, @step_id = 1, @step_name = N<span style="color: #006080">'Create File'</span>, @command = N<span style="color: #006080">'Function Main()</span>, @database_name = N<span style="color: #006080">'VBScript'</span>, @server = N<span style="color: #006080">''</span>, @database_user_name = N<span style="color: #006080">''</span>, @subsystem = N<span style="color: #006080">'ActiveScripting'</span>, @cmdexec_success_code = 0, @flags = 0, @retry_attempts = 0, @retry_interval = 1, @output_file_name = N<span style="color: #006080">''</span>, @on_success_step_id = 0, @on_success_action = 3, @on_fail_step_id = 0, @on_fail_action = 2</pre>
<p><!--CRLF--></p>
<pre style="text-align: left; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">  FileName = "C:\Test.txt"</pre>
<p><!--CRLF--></p>
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">  Dim fso, f1</pre>
<p><!--CRLF--></p>
<p><!--CRLF--></p>
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">  Set fso = CreateObject("Scripting.FileSystemObject")</pre>
<p><!--CRLF--></p>
<pre style="text-align: left; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">  Set f1 = fso.CreateTextFile(FileName, True)</pre>
<p><!--CRLF--></p>
<p><!--CRLF--></p>
<pre style="text-align: left; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">  Set fso = Nothing</pre>
<p><!--CRLF--></p>
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">  Set f1 = Nothing</pre>
<p><!--CRLF--></p>
<pre style="text-align: left; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">End Function'</pre>
<p><!--CRLF--></p>
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">  <span style="color: #0000ff">IF</span> (@@ERROR &lt;&gt; 0 <span style="color: #0000ff">OR</span> @ReturnCode &lt;&gt; 0) <span style="color: #0000ff">GOTO</span> QuitWithRollback</pre>
<p><!--CRLF--></p>
<pre style="text-align: left; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">  <span style="color: #0000ff">EXECUTE</span> @ReturnCode = msdb.dbo.sp_add_jobstep @job_id = @JobID, @step_id = 2, @step_name = N<span style="color: #006080">'Find File'</span>, @command = N<span style="color: #006080">'</span><span style="color: #006080">' Clean Up</span>, @database_name = N<span style="color: #006080">'VBScript'</span>, @server = N<span style="color: #006080">''</span>, @database_user_name = N<span style="color: #006080">''</span>, @subsystem = N<span style="color: #006080">'ActiveScripting'</span>, @cmdexec_success_code = 0, @flags = 0, @retry_attempts = 0, @retry_interval = 1, @output_file_name = N<span style="color: #006080">''</span>, @on_success_step_id = 0, @on_success_action = 3, @on_fail_step_id = 4, @on_fail_action = 4</pre>
<p><!--CRLF--></p>
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">Function Main()</pre>
<p><!--CRLF--></p>
<p><!--CRLF--></p>
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">      Dim FSO</pre>
<p><!--CRLF--></p>
<pre style="text-align: left; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">      Dim File</pre>
<p><!--CRLF--></p>
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">      Dim SourceFile</pre>
<p><!--CRLF--></p>
<p><!--CRLF--></p>
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">      Set FSO = CreateObject("Scripting.FileSystemObject")</pre>
<p><!--CRLF--></p>
<p><!--CRLF--></p>
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">      FileName = "C:\ThisIsntWhatICreated.txt"</pre>
<p><!--CRLF--></p>
<p><!--CRLF--></p>
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">      If NOT FSO.FileExists(FileName) Then</pre>
<p><!--CRLF--></p>
<pre style="text-align: left; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">             Call Err.Raise(60001, "File Not found")</pre>
<p><!--CRLF--></p>
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">      End If</pre>
<p><!--CRLF--></p>
<p><!--CRLF--></p>
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">      '</pre>
<p><!--CRLF--></p>
<pre style="text-align: left; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">      Set File = Nothing</pre>
<p><!--CRLF--></p>
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">      Set FSO = Nothing</pre>
<p><!--CRLF--></p>
<pre style="text-align: left; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">End Function'</pre>
<p><!--CRLF--></p>
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">  <span style="color: #0000ff">IF</span> (@@ERROR &lt;&gt; 0 <span style="color: #0000ff">OR</span> @ReturnCode &lt;&gt; 0) <span style="color: #0000ff">GOTO</span> QuitWithRollback</pre>
<p><!--CRLF--></p>
<pre style="text-align: left; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">  <span style="color: #0000ff">EXECUTE</span> @ReturnCode = msdb.dbo.sp_add_jobstep @job_id = @JobID, @step_id = 3, @step_name = N<span style="color: #006080">'Delete File'</span>, @command = N<span style="color: #006080">'Function Main()</span><span style="color: #006080">' Check if file exists to prevent error</span><span style="color: #006080">' Clean Up</span>, @database_name = N<span style="color: #006080">'VBScript'</span>, @server = N<span style="color: #006080">''</span>, @database_user_name = N<span style="color: #006080">''</span>, @subsystem = N<span style="color: #006080">'ActiveScripting'</span>, @cmdexec_success_code = 0, @flags = 0, @retry_attempts = 0, @retry_interval = 1, @output_file_name = N<span style="color: #006080">''</span>, @on_success_step_id = 0, @on_success_action = 1, @on_fail_step_id = 0, @on_fail_action = 2</pre>
<p><!--CRLF--></p>
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">      Dim oFSO</pre>
<p><!--CRLF--></p>
<pre style="text-align: left; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">      Dim sSourceFile</pre>
<p><!--CRLF--></p>
<p><!--CRLF--></p>
<pre style="text-align: left; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">      Set oFSO = CreateObject("Scripting.FileSystemObject")</pre>
<p><!--CRLF--></p>
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">      sSourceFile = "C:\Test.txt"</pre>
<p><!--CRLF--></p>
<p><!--CRLF--></p>
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">      '</pre>
<p><!--CRLF--></p>
<pre style="text-align: left; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">      If oFSO.FileExists(sSourceFile) Then</pre>
<p><!--CRLF--></p>
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">            oFSO.DeleteFile sSourceFile</pre>
<p><!--CRLF--></p>
<pre style="text-align: left; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">      End If</pre>
<p><!--CRLF--></p>
<p><!--CRLF--></p>
<pre style="text-align: left; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">      '</pre>
<p><!--CRLF--></p>
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">      Set oFSO = Nothing</pre>
<p><!--CRLF--></p>
<p><!--CRLF--></p>
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">End Function</pre>
<p><!--CRLF--></p>
<pre style="text-align: left; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">'</pre>
<p><!--CRLF--></p>
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">  <span style="color: #0000ff">IF</span> (@@ERROR &lt;&gt; 0 <span style="color: #0000ff">OR</span> @ReturnCode &lt;&gt; 0) <span style="color: #0000ff">GOTO</span> QuitWithRollback</pre>
<p><!--CRLF--></p>
<pre style="text-align: left; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">  <span style="color: #0000ff">EXECUTE</span> @ReturnCode = msdb.dbo.sp_add_jobstep @job_id = @JobID, @step_id = 4, @step_name = N<span style="color: #006080">'Job Failed'</span>, @command = N<span style="color: #006080">'select 1'</span>, @database_name = N<span style="color: #006080">'master'</span>, @server = N<span style="color: #006080">''</span>, @database_user_name = N<span style="color: #006080">''</span>, @subsystem = N<span style="color: #006080">'TSQL'</span>, @cmdexec_success_code = 0, @flags = 0, @retry_attempts = 0, @retry_interval = 1, @output_file_name = N<span style="color: #006080">''</span>, @on_success_step_id = 0, @on_success_action = 2, @on_fail_step_id = 0, @on_fail_action = 2</pre>
<p><!--CRLF--></p>
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">  <span style="color: #0000ff">IF</span> (@@ERROR &lt;&gt; 0 <span style="color: #0000ff">OR</span> @ReturnCode &lt;&gt; 0) <span style="color: #0000ff">GOTO</span> QuitWithRollback</pre>
<p><!--CRLF--></p>
<pre style="text-align: left; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">  <span style="color: #0000ff">EXECUTE</span> @ReturnCode = msdb.dbo.sp_update_job @job_id = @JobID, @start_step_id = 1</pre>
<p><!--CRLF--></p>
<p><!--CRLF--></p>
<pre style="text-align: left; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">  <span style="color: #0000ff">IF</span> (@@ERROR &lt;&gt; 0 <span style="color: #0000ff">OR</span> @ReturnCode &lt;&gt; 0) <span style="color: #0000ff">GOTO</span> QuitWithRollback</pre>
<p><!--CRLF--></p>
<p><!--CRLF--></p>
<pre style="text-align: left; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">  <span style="color: #008000">-- Add the Target Servers</span></pre>
<p><!--CRLF--></p>
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">  <span style="color: #0000ff">EXECUTE</span> @ReturnCode = msdb.dbo.sp_add_jobserver @job_id = @JobID, @server_name = N<span style="color: #006080">'(local)'</span></pre>
<p><!--CRLF--></p>
<pre style="text-align: left; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">  <span style="color: #0000ff">IF</span> (@@ERROR &lt;&gt; 0 <span style="color: #0000ff">OR</span> @ReturnCode &lt;&gt; 0) <span style="color: #0000ff">GOTO</span> QuitWithRollback</pre>
<p><!--CRLF--></p>
<p><!--CRLF--></p>
<pre style="text-align: left; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #0000ff">END</span></pre>
<p><!--CRLF--></p>
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #0000ff">COMMIT</span> <span style="color: #0000ff">TRANSACTION</span></pre>
<p><!--CRLF--></p>
<pre style="text-align: left; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #0000ff">GOTO</span>   EndSave</pre>
<p><!--CRLF--></p>
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">QuitWithRollback:</pre>
<p><!--CRLF--></p>
<pre style="text-align: left; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">  <span style="color: #0000ff">IF</span> (@@TRANCOUNT &gt; 0) <span style="color: #0000ff">ROLLBACK</span> <span style="color: #0000ff">TRANSACTION</span></pre>
<p><!--CRLF--></p>
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">EndSave:</pre>
<p><!--CRLF--></p>
<pre style="text-align: left; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"> </pre>
<p><!--CRLF--></div>
</div>
<div> </div>
<div>The first time you run this job it should fail (unless of course you have the file C:\ThisIsntWhatICreated.txt) having run steps 1,2 and 4. If you change the second step to now look for the file C:\Test.txt for job should succeed in running the first three steps.</div>
<p>This has been a very simple overview of a few of the methods of the FileSystemObject, there are many more things you can do for example you may only want to proceed if the file is a certain size or of a certain date, with the FileSystemObject you can do all this and more. In fact I’ll show you how you can check the file size as well, this time we’ll use DTS (I realise it’s now two versions out of date but from the people I have spoken to lots of companies still use SQL 2000, even SQL 7 and still develop in DTS).</p>
<p>You can download the package <a href="http://cid-79ed191e1aa4b914.skydrive.live.com/self.aspx/.Public/Find%20Files%20-%20ActiveX.dts" target="_blank">here</a>.</p>
<p>If you don’t want to download the package then the code below is the crux of it:</p>
<div id="codeSnippetWrapper">
<div id="codeSnippet" style="text-align: left; line-height: 12pt; background-color: #f4f4f4; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">
<pre style="text-align: left; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #008000">'**********************************************************************</span></pre>
<p><!--CRLF--></p>
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #008000">'  Visual Basic ActiveX Script</span></pre>
<p><!--CRLF--></p>
<pre style="text-align: left; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #008000">'************************************************************************</span></pre>
<p><!--CRLF--></p>
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"> </pre>
<p><!--CRLF--></p>
<pre style="text-align: left; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #0000ff">Function</span> Main()</pre>
<p><!--CRLF--></p>
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"> </pre>
<p><!--CRLF--></p>
<pre style="text-align: left; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">    <span style="color: #0000ff">Dim</span> FSO</pre>
<p><!--CRLF--></p>
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">    <span style="color: #0000ff">Dim</span> File</pre>
<p><!--CRLF--></p>
<pre style="text-align: left; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">    <span style="color: #0000ff">Dim</span> SourceFile</pre>
<p><!--CRLF--></p>
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"> </pre>
<p><!--CRLF--></p>
<pre style="text-align: left; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">    <span style="color: #0000ff">Set</span> FSO = CreateObject(<span style="color: #006080">"Scripting.FileSystemObject"</span>)</pre>
<p><!--CRLF--></p>
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"> </pre>
<p><!--CRLF--></p>
<pre style="text-align: left; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">    FileName = DTSGlobalVariables(<span style="color: #006080">"FileName"</span>).Value</pre>
<p><!--CRLF--></p>
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"> </pre>
<p><!--CRLF--></p>
<pre style="text-align: left; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">    <span style="color: #0000ff">If</span> FSO.FileExists(FileName) <span style="color: #0000ff">Then</span></pre>
<p><!--CRLF--></p>
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">        <span style="color: #0000ff">Set</span> File = FSO.GetFile(FileName)</pre>
<p><!--CRLF--></p>
<pre style="text-align: left; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"> </pre>
<p><!--CRLF--></p>
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">        <span style="color: #0000ff">If</span> File.Size = 0 <span style="color: #0000ff">Then</span></pre>
<p><!--CRLF--></p>
<pre style="text-align: left; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">            Main = DTSTaskExecResult_Success</pre>
<p><!--CRLF--></p>
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">        <span style="color: #0000ff">Else</span></pre>
<p><!--CRLF--></p>
<pre style="text-align: left; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">            Main = DTSTaskExecResult_Failure</pre>
<p><!--CRLF--></p>
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">        <span style="color: #0000ff">End</span> <span style="color: #0000ff">If</span></pre>
<p><!--CRLF--></p>
<pre style="text-align: left; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">    <span style="color: #0000ff">Else</span></pre>
<p><!--CRLF--></p>
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">        Main = DTSTaskExecResult_Failure</pre>
<p><!--CRLF--></p>
<pre style="text-align: left; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">    <span style="color: #0000ff">End</span> <span style="color: #0000ff">If</span></pre>
<p><!--CRLF--></p>
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"> </pre>
<p><!--CRLF--></p>
<pre style="text-align: left; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">    <span style="color: #008000">' Clean Up</span></pre>
<p><!--CRLF--></p>
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">    <span style="color: #0000ff">Set</span> File = <span style="color: #0000ff">Nothing</span></pre>
<p><!--CRLF--></p>
<pre style="text-align: left; line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">    <span style="color: #0000ff">Set</span> FSO = <span style="color: #0000ff">Nothing</span></pre>
<p><!--CRLF--></p>
<pre style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #0000ff">End</span> <span style="color: #0000ff">Function</span></pre>
<p><!--CRLF--></div>
</div>
<p>As you can see it’s pretty similar to the ActiveX we used in step two of the job with a couple of differences. The first being that we are using a global variable for the filename, this is so we could use it in a loop, read it from a table or any number of other things.</p>
<p>The second is that we are now also using the GetFile method that allows us to check the properties of the file itself. In this scenario we are looking at the size and saying if the file size is 0 then succeed, else fail.</p>
<p>To find out more about how to use the FileSystemObject you can refer to the MSDN documentation <a href="http://msdn.microsoft.com/en-us/library/6kxy1a51(VS.85).aspx" target="_blank">here</a>. I hope you have found this an interesting introduction to the FileSystemObject and thank you for reading.</p>
]]></content:encoded>
			<wfw:commentRss>http://sql.richarddouglas.co.uk/archive/2009/11/finding-files-part-2-activex.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
