<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/rss2full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><rss 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/" version="2.0">

<channel>
	<title>Rick Caminiti dotCOM »  – Rick Caminiti dotCom</title>
	
	<link>http://rickcaminiti.com</link>
	<description>Me, Myself, and IT</description>
	<lastBuildDate>Sat, 19 Mar 2011 03:35:38 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/rss+xml" href="http://feeds.feedburner.com/RickCaminitiDotcom" /><feedburner:info xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" uri="rickcaminitidotcom" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><item>
		<title>T-SQL Get Week (Day of Week) UDF</title>
		<link>http://rickcaminiti.com/bi/tsql-week-day-week-udf/</link>
		<comments>http://rickcaminiti.com/bi/tsql-week-day-week-udf/#comments</comments>
		<pubDate>Wed, 01 Jul 2009 14:32:29 +0000</pubDate>
		<dc:creator>NothingMan</dc:creator>
				<category><![CDATA[BI]]></category>
		<category><![CDATA[Code]]></category>
		<category><![CDATA[date]]></category>
		<category><![CDATA[format]]></category>
		<category><![CDATA[mssql]]></category>
		<category><![CDATA[sql]]></category>
		<category><![CDATA[t-sql]]></category>
		<category><![CDATA[Tips]]></category>

		<guid isPermaLink="false">http://rickcaminiti.com/?p=391</guid>
		<description>SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE FUNCTION getWeekByDoW (       &amp;#8211; Add the parameters for the function here       @date datetime,     @day    varchar(3) ) RETURNS datetime AS BEGIN       DECLARE @dowNum   int,                   @truncDate datetime,                   @retDate datetime;         select @truncDate = cast(convert(varchar, @date, 101) as datetime)            ,@dowNum = [...]</description>
			<content:encoded><![CDATA[<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; color: blue; font-family: &quot;Courier New&quot;; mso-no-proof: yes;">SET</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"> <span style="color: blue;">ANSI_NULLS</span> <span style="color: blue;">ON</span></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;">GO</span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; color: blue; font-family: &quot;Courier New&quot;; mso-no-proof: yes;">SET</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"> <span style="color: blue;">QUOTED_IDENTIFIER</span> <span style="color: blue;">ON</span></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;">GO</span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; color: blue; font-family: &quot;Courier New&quot;; mso-no-proof: yes;">CREATE</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"> <span style="color: blue;">FUNCTION</span> getWeekByDoW</span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; color: gray; font-family: &quot;Courier New&quot;; mso-no-proof: yes;">(</span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-tab-count: 1;">      </span><span style="color: green;">&#8211; Add the parameters for the function here</span></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-tab-count: 1;">      </span>@date<span style="mso-tab-count: 1;"> </span><span style="color: blue;">datetime</span><span style="color: gray;">,</span> </span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;">    </span>@day<span style="mso-tab-count: 1;">    </span><span style="color: blue;">varchar</span><span style="color: gray;">(</span>3<span style="color: gray;">)</span></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; color: gray; font-family: &quot;Courier New&quot;; mso-no-proof: yes;">)</span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; color: blue; font-family: &quot;Courier New&quot;; mso-no-proof: yes;">RETURNS</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"> <span style="color: blue;">datetime</span></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; color: blue; font-family: &quot;Courier New&quot;; mso-no-proof: yes;">AS</span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; color: blue; font-family: &quot;Courier New&quot;; mso-no-proof: yes;">BEGIN</span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-tab-count: 1;">      </span><span style="color: blue;">DECLARE</span> @dowNum<span style="mso-tab-count: 1;">   </span><span style="color: blue;">int</span><span style="color: gray;">,</span> </span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-tab-count: 3;">                  </span>@truncDate <span style="color: blue;">datetime</span><span style="color: gray;">,</span> </span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-tab-count: 3;">                  </span>@retDate <span style="color: blue;">datetime</span><span style="color: gray;">;</span></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; color: gray; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"> </span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-tab-count: 1;">      </span><span style="color: blue;">select</span> @truncDate <span style="color: gray;">=</span> <span style="color: fuchsia;">cast</span><span style="color: gray;">(</span><span style="color: fuchsia;">convert</span><span style="color: gray;">(</span><span style="color: blue;">varchar</span><span style="color: gray;">,</span> @date<span style="color: gray;">,</span> 101<span style="color: gray;">)</span> <span style="color: blue;">as</span> <span style="color: blue;">datetime</span><span style="color: gray;">)</span></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;">           </span><span style="color: gray;">,</span>@dowNum <span style="color: gray;">=</span> </span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-tab-count: 3;">                  </span><span style="color: blue;">case</span> </span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-tab-count: 4;">                        </span><span style="color: blue;">when</span> @day <span style="color: gray;">=</span> <span style="color: red;">&#8216;Sun&#8217;</span> </span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-tab-count: 5;">                              </span><span style="color: blue;">then</span> 1</span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-tab-count: 4;">                        </span><span style="color: blue;">when</span> @day <span style="color: gray;">=</span> <span style="color: red;">&#8216;Mon&#8217;</span> </span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-tab-count: 5;">                              </span><span style="color: blue;">then</span> 2</span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-tab-count: 4;">                        </span><span style="color: blue;">when</span> @day <span style="color: gray;">=</span> <span style="color: red;">&#8216;Tue&#8217;</span> </span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-tab-count: 5;">                              </span><span style="color: blue;">then</span> 3</span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-tab-count: 4;">                        </span><span style="color: blue;">when</span> @day <span style="color: gray;">=</span> <span style="color: red;">&#8216;Wed&#8217;</span> </span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-tab-count: 5;">                              </span><span style="color: blue;">then</span> 4</span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-tab-count: 4;">                        </span><span style="color: blue;">when</span> @day <span style="color: gray;">=</span> <span style="color: red;">&#8216;Thu&#8217;</span> </span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-tab-count: 5;">                              </span><span style="color: blue;">then</span> 5</span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-tab-count: 4;">                        </span><span style="color: blue;">when</span> @day <span style="color: gray;">=</span> <span style="color: red;">&#8216;Fri&#8217;</span> </span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-tab-count: 5;">                              </span><span style="color: blue;">then</span> 6</span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-tab-count: 4;">                        </span><span style="color: blue;">when</span> @day <span style="color: gray;">=</span> <span style="color: red;">&#8216;Sat&#8217;</span> </span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-tab-count: 5;">                              </span><span style="color: blue;">then</span> 7</span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-tab-count: 4;">                        </span><span style="color: blue;">else</span> 0</span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-tab-count: 3;">                  </span><span style="color: blue;">end</span> </span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"> </span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-tab-count: 1;">      </span><span style="color: blue;">select</span> @retDate <span style="color: gray;">=</span> <span style="color: fuchsia;">DATEADD</span><span style="color: gray;">(</span>DD<span style="color: gray;">,</span> @dowNum <span style="color: gray;">-</span> <span style="color: fuchsia;">DATEPART</span><span style="color: gray;">(</span>DW<span style="color: gray;">,</span> @truncDate<span style="color: gray;">),</span> @truncDate<span style="color: gray;">)</span></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-tab-count: 1;">      </span><span style="color: blue;">RETURN</span> @retDate</span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; color: blue; font-family: &quot;Courier New&quot;; mso-no-proof: yes;">END</span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;">GO</span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"> </span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; color: blue; font-family: &quot;Courier New&quot;; mso-no-proof: yes;">select</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-tab-count: 1;">      </span>getWeekByDoW<span style="color: gray;">(</span><span style="color: fuchsia;">getdate</span><span style="color: gray;">(),</span> <span style="color: red;">&#8216;Sun&#8217;</span><span style="color: gray;">)</span> Sun<span style="color: gray;">,</span></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-tab-count: 2;">            </span>getWeekByDoW<span style="color: gray;">(</span><span style="color: fuchsia;">getdate</span><span style="color: gray;">(),</span> <span style="color: red;">&#8216;Mon&#8217;</span><span style="color: gray;">)</span> Mon<span style="color: gray;">,</span></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-tab-count: 2;">            </span>getWeekByDoW<span style="color: gray;">(</span><span style="color: fuchsia;">getdate</span><span style="color: gray;">(),</span> <span style="color: red;">&#8216;Tue&#8217;</span><span style="color: gray;">)</span> Tue<span style="color: gray;">,</span></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-tab-count: 2;">            </span>getWeekByDoW<span style="color: gray;">(</span><span style="color: fuchsia;">getdate</span><span style="color: gray;">(),</span> <span style="color: red;">&#8216;Wed&#8217;</span><span style="color: gray;">)</span> Wed<span style="color: gray;">,</span></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-tab-count: 2;">            </span>getWeekByDoW<span style="color: gray;">(</span><span style="color: fuchsia;">getdate</span><span style="color: gray;">(),</span> <span style="color: red;">&#8216;Thu&#8217;</span><span style="color: gray;">)</span> Thu<span style="color: gray;">,</span></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-tab-count: 2;">            </span>getWeekByDoW<span style="color: gray;">(</span><span style="color: fuchsia;">getdate</span><span style="color: gray;">(),</span> <span style="color: red;">&#8216;Fri&#8217;</span><span style="color: gray;">)</span> Fri<span style="color: gray;">,</span></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-tab-count: 2;">            </span>getWeekByDoW<span style="color: gray;">(</span><span style="color: fuchsia;">getdate</span><span style="color: gray;">(),</span> <span style="color: red;">&#8216;Sat&#8217;</span><span style="color: gray;">)</span> Sat</span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"> </span></p>
<table class="MsoNormalTable" style="margin: auto auto auto 4.8pt; width: 316pt; border-collapse: collapse; mso-padding-alt: 0in 5.4pt 0in 5.4pt;" border="0" cellspacing="0" cellpadding="0" width="421">
<tbody>
<tr style="height: 12.75pt; mso-yfti-irow: 0; mso-yfti-firstrow: yes;">
<td style="padding-right: 5.4pt; padding-left: 5.4pt; padding-bottom: 0in; width: 48pt; padding-top: 0in; height: 12.75pt; background-color: transparent; border: #ece9d8;" width="64" valign="bottom">
<p class="MsoNormal" style="margin: 0in 0in 0pt;"><strong><span style="font-size: 10pt; font-family: Arial;">Sun</span></strong></p>
</td>
<td style="padding-right: 5.4pt; padding-left: 5.4pt; padding-bottom: 0in; width: 48pt; padding-top: 0in; height: 12.75pt; background-color: transparent; border: #ece9d8;" width="64" valign="bottom">
<p class="MsoNormal" style="margin: 0in 0in 0pt;"><strong><span style="font-size: 10pt; font-family: Arial;">Mon</span></strong></p>
</td>
<td style="padding-right: 5.4pt; padding-left: 5.4pt; padding-bottom: 0in; width: 48pt; padding-top: 0in; height: 12.75pt; background-color: transparent; border: #ece9d8;" width="64" valign="bottom">
<p class="MsoNormal" style="margin: 0in 0in 0pt;"><strong><span style="font-size: 10pt; font-family: Arial;">Tue</span></strong></p>
</td>
<td style="padding-right: 5.4pt; padding-left: 5.4pt; padding-bottom: 0in; width: 43pt; padding-top: 0in; height: 12.75pt; background-color: transparent; border: #ece9d8;" width="57" valign="bottom">
<p class="MsoNormal" style="margin: 0in 0in 0pt;"><strong><span style="font-size: 10pt; font-family: Arial;">Wed</span></strong></p>
</td>
<td style="padding-right: 5.4pt; padding-left: 5.4pt; padding-bottom: 0in; width: 43pt; padding-top: 0in; height: 12.75pt; background-color: transparent; border: #ece9d8;" width="57" valign="bottom">
<p class="MsoNormal" style="margin: 0in 0in 0pt;"><strong><span style="font-size: 10pt; font-family: Arial;">Thu</span></strong></p>
</td>
<td style="padding-right: 5.4pt; padding-left: 5.4pt; padding-bottom: 0in; width: 43pt; padding-top: 0in; height: 12.75pt; background-color: transparent; border: #ece9d8;" width="57" valign="bottom">
<p class="MsoNormal" style="margin: 0in 0in 0pt;"><strong><span style="font-size: 10pt; font-family: Arial;">Fri</span></strong></p>
</td>
<td style="padding-right: 5.4pt; padding-left: 5.4pt; padding-bottom: 0in; width: 43pt; padding-top: 0in; height: 12.75pt; background-color: transparent; border: #ece9d8;" width="57" valign="bottom">
<p class="MsoNormal" style="margin: 0in 0in 0pt;"><strong><span style="font-size: 10pt; font-family: Arial;">Sat</span></strong></p>
</td>
</tr>
<tr style="height: 12.75pt; mso-yfti-irow: 1; mso-yfti-lastrow: yes;">
<td style="padding-right: 5.4pt; padding-left: 5.4pt; padding-bottom: 0in; width: 48pt; padding-top: 0in; height: 12.75pt; background-color: transparent; border: #ece9d8;" width="64" valign="bottom">
<p class="MsoNormal" style="margin: 0in 0in 0pt; text-align: right;" align="right"><span style="font-size: 10pt; font-family: Arial;">6/28/2009</span></p>
</td>
<td style="padding-right: 5.4pt; padding-left: 5.4pt; padding-bottom: 0in; width: 48pt; padding-top: 0in; height: 12.75pt; background-color: transparent; border: #ece9d8;" width="64" valign="bottom">
<p class="MsoNormal" style="margin: 0in 0in 0pt; text-align: right;" align="right"><span style="font-size: 10pt; font-family: Arial;">6/29/2009</span></p>
</td>
<td style="padding-right: 5.4pt; padding-left: 5.4pt; padding-bottom: 0in; width: 48pt; padding-top: 0in; height: 12.75pt; background-color: transparent; border: #ece9d8;" width="64" valign="bottom">
<p class="MsoNormal" style="margin: 0in 0in 0pt; text-align: right;" align="right"><span style="font-size: 10pt; font-family: Arial;">6/30/2009</span></p>
</td>
<td style="padding-right: 5.4pt; padding-left: 5.4pt; padding-bottom: 0in; width: 43pt; padding-top: 0in; height: 12.75pt; background-color: transparent; border: #ece9d8;" width="57" valign="bottom">
<p class="MsoNormal" style="margin: 0in 0in 0pt; text-align: right;" align="right"><span style="font-size: 10pt; font-family: Arial;">7/1/2009</span></p>
</td>
<td style="padding-right: 5.4pt; padding-left: 5.4pt; padding-bottom: 0in; width: 43pt; padding-top: 0in; height: 12.75pt; background-color: transparent; border: #ece9d8;" width="57" valign="bottom">
<p class="MsoNormal" style="margin: 0in 0in 0pt; text-align: right;" align="right"><span style="font-size: 10pt; font-family: Arial;">7/2/2009</span></p>
</td>
<td style="padding-right: 5.4pt; padding-left: 5.4pt; padding-bottom: 0in; width: 43pt; padding-top: 0in; height: 12.75pt; background-color: transparent; border: #ece9d8;" width="57" valign="bottom">
<p class="MsoNormal" style="margin: 0in 0in 0pt; text-align: right;" align="right"><span style="font-size: 10pt; font-family: Arial;">7/3/2009</span></p>
</td>
<td style="padding-right: 5.4pt; padding-left: 5.4pt; padding-bottom: 0in; width: 43pt; padding-top: 0in; height: 12.75pt; background-color: transparent; border: #ece9d8;" width="57" valign="bottom">
<p class="MsoNormal" style="margin: 0in 0in 0pt; text-align: right;" align="right"><span style="font-size: 10pt; font-family: Arial;">7/4/2009</span></p>
</td>
</tr>
</tbody>
</table>
<p class="MsoNormal" style="margin: 0in 0in 0pt;"><span style="font-size: small; font-family: Times New Roman;"> </span></p>
]]></content:encoded>
			<wfw:commentRss>http://rickcaminiti.com/bi/tsql-week-day-week-udf/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Using a T-SQL Cursor</title>
		<link>http://rickcaminiti.com/tips/tsql-cursor/</link>
		<comments>http://rickcaminiti.com/tips/tsql-cursor/#comments</comments>
		<pubDate>Thu, 18 Jun 2009 16:48:19 +0000</pubDate>
		<dc:creator>NothingMan</dc:creator>
				<category><![CDATA[BI]]></category>
		<category><![CDATA[Code]]></category>
		<category><![CDATA[Tips]]></category>
		<category><![CDATA[t-sql]]></category>
		<category><![CDATA[table]]></category>

		<guid isPermaLink="false">http://rickcaminiti.com/?p=388</guid>
		<description>I needed to loop through a large table by date, one month at a time and process the data.  This is the basic cursor that I wrote in T-SQL.  It&amp;#8217;s pretty straight-forward. First, you declare the cursor as a select statement. Then you open the cursor (make sure you CLOSE it and DEALLOCATE it when [...]</description>
			<content:encoded><![CDATA[<p>I needed to loop through a large table by date, one month at a time and process the data.  This is the basic cursor that I wrote in T-SQL.  It&#8217;s pretty straight-forward.</p>
<p>First, you declare the cursor as a select statement.</p>
<p>Then you open the cursor (make sure you CLOSE it and DEALLOCATE it when you&#8217;re done!!)</p>
<p>Declare cursor-scope variables to fetch the data into and fetch the data from the cursor.</p>
<p>Loop through the data while the fetch status is &#8220;SUCCESS&#8221;.</p>
<p>Then check to make sure the fetch status indicates that the row was loaded properly and do whatever processing you need to do.</p>
<p>When done processing, fetch the next row and continue looping.</p>
<p>After the looping, close the cursor and deallocate it from memory.</p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; color: blue; font-family: &quot;Courier New&quot;; mso-no-proof: yes;">DECLARE</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"> cur <span style="color: blue;">CURSOR</span></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-tab-count: 1;">      </span><span style="color: blue;">FOR</span> <span style="color: blue;">select</span> <span style="color: blue;">distinct</span><span style="mso-spacerun: yes;">  </span><span style="color: fuchsia;">cast</span><span style="color: gray;">(</span><span style="color: fuchsia;">convert</span><span style="color: gray;">(</span><span style="color: blue;">varchar</span><span style="color: gray;">(</span>25<span style="color: gray;">),</span><span style="color: fuchsia;">dateadd</span><span style="color: gray;">(</span>dd<span style="color: gray;">,-(</span><span style="color: fuchsia;">day</span><span style="color: gray;">(</span>[date_column]<span style="color: gray;">)-</span>1<span style="color: gray;">),</span>[date_column]<span style="color: gray;">),</span>101<span style="color: gray;">)</span> <span style="color: blue;">as</span> <span style="color: blue;">datetime</span><span style="color: gray;">)</span> begdate</span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-tab-count: 6;">                                    </span><span style="color: gray;">,</span><span style="color: fuchsia;">cast</span><span style="color: gray;">(</span><span style="color: fuchsia;">convert</span><span style="color: gray;">(</span><span style="color: blue;">varchar</span><span style="color: gray;">(</span>25<span style="color: gray;">),</span><span style="color: fuchsia;">dateadd</span><span style="color: gray;">(</span>dd<span style="color: gray;">,-(</span><span style="color: fuchsia;">day</span><span style="color: gray;">(</span><span style="color: fuchsia;">dateadd</span><span style="color: gray;">(</span>mm<span style="color: gray;">,</span>1<span style="color: gray;">,</span>[date_column]<span style="color: gray;">))-</span>1<span style="color: gray;">),</span><span style="color: fuchsia;">dateadd</span><span style="color: gray;">(</span>mm<span style="color: gray;">,</span>1<span style="color: gray;">,</span>[date_column]<span style="color: gray;">)),</span>101<span style="color: gray;">)</span> <span style="color: blue;">as</span> <span style="color: blue;">datetime</span><span style="color: gray;">)</span> enddate</span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-tab-count: 2;">            </span><span style="mso-spacerun: yes;">  </span><span style="color: blue;">from</span> [dbo]<span style="color: gray;">.</span>[StagingTable]</span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-tab-count: 2;">            </span><span style="mso-spacerun: yes;"> </span><span style="color: blue;">order</span> <span style="color: blue;">by</span> 1<span style="color: gray;">;</span></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; color: blue; font-family: &quot;Courier New&quot;; mso-no-proof: yes;">OPEN</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"> cur</span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-tab-count: 1;">      </span><span style="color: blue;">DECLARE</span> @begdate <span style="color: blue;">datetime</span><span style="color: gray;">,</span> @enddate <span style="color: blue;">datetime</span><span style="color: gray;">;</span></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-tab-count: 1;">      </span><span style="color: blue;">FETCH</span> <span style="color: blue;">NEXT</span> <span style="color: blue;">from</span> cur <span style="color: blue;">INTO</span> @begdate<span style="color: gray;">,</span> @enddate</span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-tab-count: 1;">      </span><span style="color: blue;">WHILE</span> <span style="color: gray;">(</span><span style="color: fuchsia;">@@FETCH_STATUS</span> <span style="color: gray;">&lt;&gt;</span> <span style="color: gray;">-</span>1<span style="color: gray;">)</span></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-tab-count: 1;">      </span><span style="color: blue;">BEGIN</span></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-tab-count: 2;">            </span><span style="color: blue;">IF</span> <span style="color: gray;">(</span><span style="color: fuchsia;">@@FETCH_STATUS</span> <span style="color: gray;">&lt;&gt;</span> <span style="color: gray;">-</span>2<span style="color: gray;">)</span></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-tab-count: 2;">            </span><span style="color: blue;">BEGIN</span><span style="mso-tab-count: 1;"> </span></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-tab-count: 4;">                        </span><span style="color: blue;">INSERT</span> <span style="color: blue;">INTO</span> [dbo]<span style="color: gray;">.</span>[DestTable]</span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-tab-count: 6;">                                    </span><span style="mso-spacerun: yes;">   </span><span style="color: gray;">(</span>[col1]</span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-tab-count: 6;">                                    </span><span style="mso-spacerun: yes;">   </span><span style="color: gray;">,</span>[col2]</span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-tab-count: 6;">                                    </span><span style="mso-spacerun: yes;">   </span><span style="color: gray;">,</span>[col3]</span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-tab-count: 6;">                                    </span><span style="mso-spacerun: yes;">   </span><span style="color: gray;">,</span>[col4]</span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-tab-count: 6;">                                    </span><span style="mso-spacerun: yes;">   </span><span style="color: gray;">,</span>[col5]<span style="color: gray;">)</span></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-tab-count: 4;">                        </span><span style="color: blue;">SELECT</span> [col1]</span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-tab-count: 5;">                              </span><span style="mso-spacerun: yes;">  </span><span style="color: gray;">,</span>[col2]</span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-tab-count: 5;">                              </span><span style="mso-spacerun: yes;">  </span><span style="color: gray;">,</span>[col3]</span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-tab-count: 5;">                              </span><span style="mso-spacerun: yes;">  </span><span style="color: gray;">,</span>[col4]</span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-tab-count: 5;">                              </span><span style="mso-spacerun: yes;">  </span><span style="color: gray;">,</span>[col5]</span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-tab-count: 4;">                        </span><span style="mso-spacerun: yes;">  </span><span style="color: blue;">FROM</span> [dbo]<span style="color: gray;">.</span>[StagingTable]</span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-tab-count: 4;">                        </span><span style="mso-spacerun: yes;"> </span><span style="color: blue;">WHERE</span> [date_column] <span style="color: gray;">&gt;=</span> @begdate</span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-tab-count: 4;">                        </span><span style="mso-spacerun: yes;">   </span><span style="color: gray;">AND</span> [date_column] <span style="color: gray;">&lt;</span> @enddate<span style="color: gray;">;</span></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; color: green; font-family: &quot;Courier New&quot;; mso-no-proof: yes;">/*SELECT @begdate begdate, @enddate enddate, @@ROWCOUNT insrows;*/</span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-tab-count: 4;">                        </span><span style="color: blue;">DELETE</span> </span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-tab-count: 4;">                        </span><span style="mso-spacerun: yes;">  </span><span style="color: blue;">FROM</span> [dbo]<span style="color: gray;">.</span>[StagingTable]</span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-tab-count: 4;">                        </span><span style="mso-spacerun: yes;"> </span><span style="color: blue;">WHERE</span> [date_column] <span style="color: gray;">&gt;=</span> @begdate</span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-tab-count: 4;">                        </span><span style="mso-spacerun: yes;">   </span><span style="color: gray;">AND</span> [date_column] <span style="color: gray;">&lt;</span> @enddate<span style="color: gray;">;</span></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; color: green; font-family: &quot;Courier New&quot;; mso-no-proof: yes;">/*SELECT @begdate begdate, @enddate enddate, @@ROWCOUNT delrows;*/</span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-tab-count: 2;">            </span><span style="color: blue;">END</span><span style="mso-tab-count: 1;">   </span></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-tab-count: 1;">      </span><span style="color: blue;">FETCH</span> <span style="color: blue;">NEXT</span> <span style="color: blue;">from</span> cur <span style="color: blue;">INTO</span> @begdate<span style="color: gray;">,</span> @enddate</span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-tab-count: 1;">      </span><span style="color: blue;">END</span></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; color: blue; font-family: &quot;Courier New&quot;; mso-no-proof: yes;">CLOSE</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"> cur</span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; color: blue; font-family: &quot;Courier New&quot;; mso-no-proof: yes;">DEALLOCATE</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"> cur</span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;">GO</span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"> </span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"> </span></p>
<table class="MsoNormalTable" style="margin: auto auto auto 4.65pt; width: 425pt; border-collapse: collapse; mso-padding-alt: 0in 5.4pt 0in 5.4pt;" border="0" cellspacing="0" cellpadding="0" width="567">
<tbody>
<tr style="height: 12.75pt; mso-yfti-irow: 0; mso-yfti-firstrow: yes;">
<td style="padding-right: 5.4pt; padding-left: 5.4pt; background: silver; padding-bottom: 0in; width: 77pt; padding-top: 0in; height: 12.75pt; mso-border-alt: solid black .5pt; border: black 1pt solid;" width="103">
<p class="MsoNormal" style="margin: 0in 0in 0pt; text-align: center;" align="center"><strong><span style="font-size: 10pt; color: black; font-family: Verdana; mso-bidi-font-family: Arial;">Return value</span></strong></p>
</td>
<td style="border-right: black 1pt solid; padding-right: 5.4pt; border-top: black 1pt solid; padding-left: 5.4pt; background: silver; padding-bottom: 0in; border-left: #ece9d8; width: 348pt; padding-top: 0in; border-bottom: black 1pt solid; height: 12.75pt; mso-border-top-alt: solid black .5pt; mso-border-bottom-alt: solid black .5pt; mso-border-right-alt: solid black .5pt;" width="464">
<p class="MsoNormal" style="margin: 0in 0in 0pt; text-align: center;" align="center"><strong><span style="font-size: 10pt; color: black; font-family: Verdana; mso-bidi-font-family: Arial;">Description</span></strong></p>
</td>
</tr>
<tr style="height: 12.75pt; mso-yfti-irow: 1;">
<td style="border-right: black 1pt solid; padding-right: 5.4pt; border-top: #ece9d8; padding-left: 5.4pt; background: silver; padding-bottom: 0in; border-left: black 1pt solid; width: 77pt; padding-top: 0in; border-bottom: black 1pt solid; height: 12.75pt; mso-border-bottom-alt: solid black .5pt; mso-border-right-alt: solid black .5pt; mso-border-left-alt: solid black .5pt;" width="103" valign="bottom">
<p class="MsoNormal" style="margin: 0in 0in 0pt; text-align: right;" align="right"><span style="font-size: 10pt; color: black; font-family: Verdana; mso-bidi-font-family: Arial;">0</span></p>
</td>
<td style="border-right: black 1pt solid; padding-right: 5.4pt; border-top: #ece9d8; padding-left: 5.4pt; background: silver; padding-bottom: 0in; border-left: #ece9d8; width: 348pt; padding-top: 0in; border-bottom: black 1pt solid; height: 12.75pt; mso-border-bottom-alt: solid black .5pt; mso-border-right-alt: solid black .5pt;" width="464" valign="bottom">
<p class="MsoNormal" style="margin: 0in 0in 0pt;"><span style="font-size: 10pt; color: black; font-family: Verdana; mso-bidi-font-family: Arial;">The FETCH statement was successful.</span></p>
</td>
</tr>
<tr style="height: 12.75pt; mso-yfti-irow: 2;">
<td style="border-right: black 1pt solid; padding-right: 5.4pt; border-top: #ece9d8; padding-left: 5.4pt; background: silver; padding-bottom: 0in; border-left: black 1pt solid; width: 77pt; padding-top: 0in; border-bottom: black 1pt solid; height: 12.75pt; mso-border-bottom-alt: solid black .5pt; mso-border-right-alt: solid black .5pt; mso-border-left-alt: solid black .5pt;" width="103" valign="bottom">
<p class="MsoNormal" style="margin: 0in 0in 0pt; text-align: right;" align="right"><span style="font-size: 10pt; color: black; font-family: Verdana; mso-bidi-font-family: Arial;">-1</span></p>
</td>
<td style="border-right: black 1pt solid; padding-right: 5.4pt; border-top: #ece9d8; padding-left: 5.4pt; background: silver; padding-bottom: 0in; border-left: #ece9d8; width: 348pt; padding-top: 0in; border-bottom: black 1pt solid; height: 12.75pt; mso-border-bottom-alt: solid black .5pt; mso-border-right-alt: solid black .5pt;" width="464" valign="bottom">
<p class="MsoNormal" style="margin: 0in 0in 0pt;"><span style="font-size: 10pt; color: black; font-family: Verdana; mso-bidi-font-family: Arial;">The FETCH statement failed or the row was beyond the result set.</span></p>
</td>
</tr>
<tr style="height: 12.75pt; mso-yfti-irow: 3; mso-yfti-lastrow: yes;">
<td style="border-right: black 1pt solid; padding-right: 5.4pt; border-top: #ece9d8; padding-left: 5.4pt; background: silver; padding-bottom: 0in; border-left: black 1pt solid; width: 77pt; padding-top: 0in; border-bottom: black 1pt solid; height: 12.75pt; mso-border-bottom-alt: solid black .5pt; mso-border-right-alt: solid black .5pt; mso-border-left-alt: solid black .5pt;" width="103" valign="bottom">
<p class="MsoNormal" style="margin: 0in 0in 0pt; text-align: right;" align="right"><span style="font-size: 10pt; color: black; font-family: Verdana; mso-bidi-font-family: Arial;">-2</span></p>
</td>
<td style="border-right: black 1pt solid; padding-right: 5.4pt; border-top: #ece9d8; padding-left: 5.4pt; background: silver; padding-bottom: 0in; border-left: #ece9d8; width: 348pt; padding-top: 0in; border-bottom: black 1pt solid; height: 12.75pt; mso-border-bottom-alt: solid black .5pt; mso-border-right-alt: solid black .5pt;" width="464" valign="bottom">
<p class="MsoNormal" style="margin: 0in 0in 0pt;"><span style="font-size: 10pt; color: black; font-family: Verdana; mso-bidi-font-family: Arial;">The row fetched is missing.</span></p>
</td>
</tr>
</tbody>
</table>
<p class="MsoNormal" style="margin: 0in 0in 0pt;"><span style="font-size: small; font-family: Times New Roman;"> </span></p>
]]></content:encoded>
			<wfw:commentRss>http://rickcaminiti.com/tips/tsql-cursor/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Getting Product and Version Information on SQL Server</title>
		<link>http://rickcaminiti.com/misc/product-version-information-sql-server/</link>
		<comments>http://rickcaminiti.com/misc/product-version-information-sql-server/#comments</comments>
		<pubDate>Wed, 17 Jun 2009 17:43:14 +0000</pubDate>
		<dc:creator>NothingMan</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[Misc]]></category>
		<category><![CDATA[Tips]]></category>
		<category><![CDATA[metadata]]></category>
		<category><![CDATA[mssql]]></category>
		<category><![CDATA[sql]]></category>

		<guid isPermaLink="false">http://rickcaminiti.com/?p=385</guid>
		<description>  SELECT SERVERPROPERTY('Edition') AS Edition,        SERVERPROPERTY('ProductLevel') AS ProductLevel,        SERVERPROPERTY('ProductVersion') AS ProductVersion Edition ProductLevel ProductVersion Enterprise Edition SP2 9.00.3282.00</description>
			<content:encoded><![CDATA[<p> <code></p>
<p class="MsoNormal" style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"><span style="FONT-SIZE: 10pt; COLOR: blue; FONT-FAMILY: 'Courier New'; mso-no-proof: yes">SELECT</span><span style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"> <span style="COLOR: fuchsia">SERVERPROPERTY</span><span style="COLOR: gray">(</span><span style="COLOR: red">'Edition'</span><span style="COLOR: gray">)</span> <span style="COLOR: blue">AS</span> Edition<span style="COLOR: gray">,</span></span></p>
<p class="MsoNormal" style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"><span style="FONT-SIZE: 10pt; COLOR: fuchsia; FONT-FAMILY: 'Courier New'; mso-no-proof: yes">       SERVERPROPERTY</span><span style="FONT-SIZE: 10pt; COLOR: gray; FONT-FAMILY: 'Courier New'; mso-no-proof: yes">(</span><span style="FONT-SIZE: 10pt; COLOR: red; FONT-FAMILY: 'Courier New'; mso-no-proof: yes">'ProductLevel'</span><span style="FONT-SIZE: 10pt; COLOR: gray; FONT-FAMILY: 'Courier New'; mso-no-proof: yes">)</span><span style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"> <span style="COLOR: blue">AS</span> ProductLevel<span style="COLOR: gray">,</span></span></p>
<p class="MsoNormal" style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"><span style="FONT-SIZE: 10pt; COLOR: fuchsia; FONT-FAMILY: 'Courier New'; mso-no-proof: yes">       SERVERPROPERTY</span><span style="FONT-SIZE: 10pt; COLOR: gray; FONT-FAMILY: 'Courier New'; mso-no-proof: yes">(</span><span style="FONT-SIZE: 10pt; COLOR: red; FONT-FAMILY: 'Courier New'; mso-no-proof: yes">'ProductVersion'</span><span style="FONT-SIZE: 10pt; COLOR: gray; FONT-FAMILY: 'Courier New'; mso-no-proof: yes">)</span><span style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"> <span style="COLOR: blue">AS</span> ProductVersion</span></p>
<p></code></p>
<table class="MsoNormalTable" style="margin: auto auto auto 4.65pt; width: 268.2pt; border-collapse: collapse; mso-padding-alt: 0in 5.4pt 0in 5.4pt;" border="0" cellspacing="0" cellpadding="0" width="358">
<tbody>
<tr style="height: 12.75pt; mso-yfti-irow: 0; mso-yfti-firstrow: yes;">
<td style="padding-right: 5.4pt; padding-left: 5.4pt; padding-bottom: 0in; width: 108.75pt; padding-top: 0in; height: 12.75pt; background-color: transparent; mso-border-alt: solid windowtext .5pt; border: windowtext 1pt solid;" width="145" valign="bottom">
<p class="MsoNormal" style="margin: 0in 0in 0pt;"><strong><span style="font-size: 10pt; font-family: Arial;">Edition</span></strong></p>
</td>
<td style="border-right: windowtext 1pt solid; padding-right: 5.4pt; border-top: windowtext 1pt solid; padding-left: 5.4pt; padding-bottom: 0in; border-left: #ece9d8; width: 99pt; padding-top: 0in; border-bottom: windowtext 1pt solid; height: 12.75pt; background-color: transparent; mso-border-top-alt: solid windowtext .5pt; mso-border-bottom-alt: solid windowtext .5pt; mso-border-right-alt: solid windowtext .5pt;" width="132" valign="bottom">
<p class="MsoNormal" style="margin: 0in 0in 0pt;"><strong><span style="font-size: 10pt; font-family: Arial;">ProductLevel</span></strong></p>
</td>
<td style="border-right: windowtext 1pt solid; padding-right: 5.4pt; border-top: windowtext 1pt solid; padding-left: 5.4pt; padding-bottom: 0in; border-left: #ece9d8; width: 60.45pt; padding-top: 0in; border-bottom: windowtext 1pt solid; height: 12.75pt; background-color: transparent; mso-border-top-alt: solid windowtext .5pt; mso-border-bottom-alt: solid windowtext .5pt; mso-border-right-alt: solid windowtext .5pt;" width="81" valign="bottom">
<p class="MsoNormal" style="margin: 0in 0in 0pt;"><strong><span style="font-size: 10pt; font-family: Arial;">ProductVersion</span></strong></p>
</td>
</tr>
<tr style="height: 12.75pt; mso-yfti-irow: 1; mso-yfti-lastrow: yes;">
<td style="border-right: windowtext 1pt solid; padding-right: 5.4pt; border-top: #ece9d8; padding-left: 5.4pt; padding-bottom: 0in; border-left: windowtext 1pt solid; width: 108.75pt; padding-top: 0in; border-bottom: windowtext 1pt solid; height: 12.75pt; background-color: transparent; mso-border-bottom-alt: solid windowtext .5pt; mso-border-right-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt;" width="145" valign="bottom">
<p class="MsoNormal" style="margin: 0in 0in 0pt;"><span style="font-size: 10pt; font-family: Arial;">Enterprise</span><span style="font-size: 10pt; font-family: Arial;"> Edition</span></p>
</td>
<td style="border-right: windowtext 1pt solid; padding-right: 5.4pt; border-top: #ece9d8; padding-left: 5.4pt; padding-bottom: 0in; border-left: #ece9d8; width: 99pt; padding-top: 0in; border-bottom: windowtext 1pt solid; height: 12.75pt; background-color: transparent; mso-border-bottom-alt: solid windowtext .5pt; mso-border-right-alt: solid windowtext .5pt;" width="132" valign="bottom">
<p class="MsoNormal" style="margin: 0in 0in 0pt;"><span style="font-size: 10pt; font-family: Arial;">SP2</span></p>
</td>
<td style="border-right: windowtext 1pt solid; padding-right: 5.4pt; border-top: #ece9d8; padding-left: 5.4pt; padding-bottom: 0in; border-left: #ece9d8; width: 60.45pt; padding-top: 0in; border-bottom: windowtext 1pt solid; height: 12.75pt; background-color: transparent; mso-border-bottom-alt: solid windowtext .5pt; mso-border-right-alt: solid windowtext .5pt;" width="81" valign="bottom">
<p class="MsoNormal" style="margin: 0in 0in 0pt;"><span style="font-size: 10pt; font-family: Arial;">9.00.3282.00</span></p>
</td>
</tr>
</tbody>
</table>
]]></content:encoded>
			<wfw:commentRss>http://rickcaminiti.com/misc/product-version-information-sql-server/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Rpad and Lpad Equivalent in T-SQL</title>
		<link>http://rickcaminiti.com/tips/rpad-lpad-equivalent-tsql/</link>
		<comments>http://rickcaminiti.com/tips/rpad-lpad-equivalent-tsql/#comments</comments>
		<pubDate>Tue, 16 Jun 2009 18:11:02 +0000</pubDate>
		<dc:creator>NothingMan</dc:creator>
				<category><![CDATA[BI]]></category>
		<category><![CDATA[Code]]></category>
		<category><![CDATA[Tips]]></category>
		<category><![CDATA[equivalents]]></category>
		<category><![CDATA[mssql]]></category>
		<category><![CDATA[oracle]]></category>
		<category><![CDATA[sql]]></category>
		<category><![CDATA[string]]></category>
		<category><![CDATA[t-sql]]></category>
		<category><![CDATA[udf]]></category>

		<guid isPermaLink="false">http://rickcaminiti.com/?p=381</guid>
		<description> Somehow, there&amp;#8217;s no built-in function equivalent to Oracle&amp;#8217;s LPAD or RPAD in SQL.  There are several ways to do this, in fact, I posted another way to do RPAD at http://rickcaminiti.com/bi/t-sql-equivalent-of-oracles-rpad/.  Unfortunately, this leaor ves no way to do an LPAD. So here&amp;#8217;s the scenario:  You have, let&amp;#8217;s say an account number that is stored as a [...]</description>
			<content:encoded><![CDATA[<p> Somehow, there&#8217;s no built-in function equivalent to Oracle&#8217;s LPAD or RPAD in SQL.  There are several ways to do this, in fact, I posted another way to do RPAD at <a href="http://rickcaminiti.com/bi/t-sql-equivalent-of-oracles-rpad/">http://rickcaminiti.com/bi/t-sql-equivalent-of-oracles-rpad/</a>.  Unfortunately, this leaor<br />
ves no way to do an LPAD.</p>
<p>So here&#8217;s the scenario:  You have, let&#8217;s say an account number that is stored as a number in one system and as a char in another system with leading zeros.  So, 123 might look like 000123 in the other system.  So if you need to represent 123 as 000123, you need to turn it into a char(6) and add 3 zeros to the begining.  That&#8217;s exactly what this LPAD function would do. </p>
<p class="MsoNormal" style="MARGIN: 0in 0in 0pt"><strong><span style="FONT-SIZE: 10pt; COLOR: blue; FONT-FAMILY: 'Courier New'"><code>CREATE</span></strong><strong><span style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 'Courier New'"> </span></strong><strong><span style="FONT-SIZE: 10pt; COLOR: blue; FONT-FAMILY: 'Courier New'">FUNCTION</span></strong><strong><span style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 'Courier New'"> LPAD </span></strong><strong><span style="FONT-SIZE: 11pt; COLOR: black; FONT-FAMILY: Calibri"></span></strong></p>
<p class="MsoNormal" style="MARGIN: 0in 0in 0pt"><strong><span style="FONT-SIZE: 10pt; COLOR: blue; FONT-FAMILY: 'Courier New'">               </span></strong><strong><span style="FONT-SIZE: 10pt; COLOR: navy; FONT-FAMILY: 'Courier New'">(</span></strong><strong><span style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 'Courier New'">@SourceString </span></strong><strong><span style="FONT-SIZE: 10pt; COLOR: blue; FONT-FAMILY: 'Courier New'">VARCHAR</span></strong><strong><span style="FONT-SIZE: 10pt; COLOR: navy; FONT-FAMILY: 'Courier New'">(</span></strong><strong><span style="FONT-SIZE: 10pt; COLOR: fuchsia; FONT-FAMILY: 'Courier New'">MAX</span></strong><strong><span style="FONT-SIZE: 10pt; COLOR: navy; FONT-FAMILY: 'Courier New'">),</span></strong><strong><span style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 'Courier New'"> </span></strong><strong><span style="FONT-SIZE: 11pt; COLOR: black; FONT-FAMILY: Calibri"></span></strong></p>
<p class="MsoNormal" style="MARGIN: 0in 0in 0pt"><strong><span style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 'Courier New'">                @FinalLength  </span></strong><strong><span style="FONT-SIZE: 10pt; COLOR: blue; FONT-FAMILY: 'Courier New'">INT</span></strong><strong><span style="FONT-SIZE: 10pt; COLOR: navy; FONT-FAMILY: 'Courier New'">,</span></strong><strong><span style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 'Courier New'"> </span></strong><strong><span style="FONT-SIZE: 11pt; COLOR: black; FONT-FAMILY: Calibri"></span></strong></p>
<p class="MsoNormal" style="MARGIN: 0in 0in 0pt"><strong><span style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 'Courier New'">                @PadChar      </span></strong><strong><span style="FONT-SIZE: 10pt; COLOR: blue; FONT-FAMILY: 'Courier New'">CHAR</span></strong><strong><span style="FONT-SIZE: 10pt; COLOR: navy; FONT-FAMILY: 'Courier New'">(</span></strong><strong><span style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 'Courier New'">1</span></strong><strong><span style="FONT-SIZE: 10pt; COLOR: navy; FONT-FAMILY: 'Courier New'">))</span></strong><strong><span style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 'Courier New'"> </span></strong><strong><span style="FONT-SIZE: 11pt; COLOR: black; FONT-FAMILY: Calibri"></span></strong></p>
<p class="MsoNormal" style="MARGIN: 0in 0in 0pt"><strong><span style="FONT-SIZE: 10pt; COLOR: blue; FONT-FAMILY: 'Courier New'">RETURNS</span></strong><strong><span style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 'Courier New'"> </span></strong><strong><span style="FONT-SIZE: 10pt; COLOR: blue; FONT-FAMILY: 'Courier New'">VARCHAR</span></strong><strong><span style="FONT-SIZE: 10pt; COLOR: navy; FONT-FAMILY: 'Courier New'">(</span></strong><strong><span style="FONT-SIZE: 10pt; COLOR: fuchsia; FONT-FAMILY: 'Courier New'">MAX</span></strong><strong><span style="FONT-SIZE: 10pt; COLOR: navy; FONT-FAMILY: 'Courier New'">)</span></strong><strong><span style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 'Courier New'"> </span></strong><strong><span style="FONT-SIZE: 11pt; COLOR: black; FONT-FAMILY: Calibri"></span></strong></p>
<p class="MsoNormal" style="MARGIN: 0in 0in 0pt"><strong><span style="FONT-SIZE: 10pt; COLOR: blue; FONT-FAMILY: 'Courier New'">AS</span></strong><strong><span style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 'Courier New'"> </span></strong><strong><span style="FONT-SIZE: 11pt; COLOR: black; FONT-FAMILY: Calibri"></span></strong></p>
<p class="MsoNormal" style="MARGIN: 0in 0in 0pt"><strong><span style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 'Courier New'">  </span></strong><strong><span style="FONT-SIZE: 10pt; COLOR: blue; FONT-FAMILY: 'Courier New'">BEGIN</span></strong><strong><span style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 'Courier New'"> </span></strong><strong><span style="FONT-SIZE: 11pt; COLOR: black; FONT-FAMILY: Calibri"></span></strong></p>
<p class="MsoNormal" style="MARGIN: 0in 0in 0pt"><strong><span style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 'Courier New'">    </span></strong><strong><span style="FONT-SIZE: 10pt; COLOR: blue; FONT-FAMILY: 'Courier New'">RETURN</span></strong><strong><span style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 'Courier New'"> </span></strong><strong><span style="FONT-SIZE: 11pt; COLOR: black; FONT-FAMILY: Calibri"></span></strong></p>
<p class="MsoNormal" style="MARGIN: 0in 0in 0pt"><strong><span style="FONT-SIZE: 10pt; COLOR: blue; FONT-FAMILY: 'Courier New'">      </span></strong><strong><span style="FONT-SIZE: 10pt; COLOR: navy; FONT-FAMILY: 'Courier New'">(</span></strong><strong><span style="FONT-SIZE: 10pt; COLOR: blue; FONT-FAMILY: 'Courier New'">SELECT</span></strong><strong><span style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 'Courier New'"> </span></strong><strong><span style="FONT-SIZE: 10pt; COLOR: fuchsia; FONT-FAMILY: 'Courier New'">Replicate</span></strong><strong><span style="FONT-SIZE: 10pt; COLOR: navy; FONT-FAMILY: 'Courier New'">(</span></strong><strong><span style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 'Courier New'">@PadChar</span></strong><strong><span style="FONT-SIZE: 10pt; COLOR: navy; FONT-FAMILY: 'Courier New'">,</span></strong><strong><span style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 'Courier New'">@FinalLength </span></strong><strong><span style="FONT-SIZE: 10pt; COLOR: navy; FONT-FAMILY: 'Courier New'">-</span></strong><strong><span style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 'Courier New'"> </span></strong><strong><span style="FONT-SIZE: 10pt; COLOR: fuchsia; FONT-FAMILY: 'Courier New'">Len</span></strong><strong><span style="FONT-SIZE: 10pt; COLOR: navy; FONT-FAMILY: 'Courier New'">(</span></strong><strong><span style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 'Courier New'">@SourceString</span></strong><strong><span style="FONT-SIZE: 10pt; COLOR: navy; FONT-FAMILY: 'Courier New'">))</span></strong><strong><span style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 'Courier New'"> </span></strong><strong><span style="FONT-SIZE: 10pt; COLOR: navy; FONT-FAMILY: 'Courier New'">+</span></strong><strong><span style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 'Courier New'"> @SourceString</span></strong><strong><span style="FONT-SIZE: 10pt; COLOR: navy; FONT-FAMILY: 'Courier New'">)</span></strong><strong><span style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 'Courier New'"> </span></strong><strong><span style="FONT-SIZE: 11pt; COLOR: black; FONT-FAMILY: Calibri"></span></strong></p>
<p class="MsoNormal" style="MARGIN: 0in 0in 0pt"><strong><span style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 'Courier New'">  </span></strong><strong><span style="FONT-SIZE: 10pt; COLOR: blue; FONT-FAMILY: 'Courier New'">END</span></strong><strong><span style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 'Courier New'"> </span></strong><strong><span style="FONT-SIZE: 11pt; COLOR: black; FONT-FAMILY: Calibri"></span></strong></p>
<p class="MsoNormal" style="MARGIN: 0in 0in 0pt"><strong><span style="FONT-SIZE: 10pt; COLOR: blue; FONT-FAMILY: 'Courier New'">GO</span></strong><strong><span style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 'Courier New'"> </span></strong><strong><span style="FONT-SIZE: 11pt; COLOR: black; FONT-FAMILY: Calibri"></span></strong></p>
<p class="MsoNormal" style="MARGIN: 0in 0in 0pt"><strong><span style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 'Courier New'"> </span></strong></p>
<p class="MsoNormal" style="MARGIN: 0in 0in 0pt"><strong><span style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 'Courier New'"> </span></strong></p>
<p class="MsoNormal" style="MARGIN: 0in 0in 0pt"><strong><span style="FONT-SIZE: 10pt; COLOR: blue; FONT-FAMILY: 'Courier New'">REATE</span></strong><strong><span style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 'Courier New'"> </span></strong><strong><span style="FONT-SIZE: 10pt; COLOR: blue; FONT-FAMILY: 'Courier New'">FUNCTION</span></strong><strong><span style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 'Courier New'"> RPAD </span></strong><strong><span style="FONT-SIZE: 11pt; COLOR: black; FONT-FAMILY: Calibri"></span></strong></p>
<p class="MsoNormal" style="MARGIN: 0in 0in 0pt"><strong><span style="FONT-SIZE: 10pt; COLOR: blue; FONT-FAMILY: 'Courier New'">               </span></strong><strong><span style="FONT-SIZE: 10pt; COLOR: navy; FONT-FAMILY: 'Courier New'">(</span></strong><strong><span style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 'Courier New'">@SourceString </span></strong><strong><span style="FONT-SIZE: 10pt; COLOR: blue; FONT-FAMILY: 'Courier New'">VARCHAR</span></strong><strong><span style="FONT-SIZE: 10pt; COLOR: navy; FONT-FAMILY: 'Courier New'">(</span></strong><strong><span style="FONT-SIZE: 10pt; COLOR: fuchsia; FONT-FAMILY: 'Courier New'">MAX</span></strong><strong><span style="FONT-SIZE: 10pt; COLOR: navy; FONT-FAMILY: 'Courier New'">),</span></strong><strong><span style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 'Courier New'"> </span></strong><strong><span style="FONT-SIZE: 11pt; COLOR: black; FONT-FAMILY: Calibri"></span></strong></p>
<p class="MsoNormal" style="MARGIN: 0in 0in 0pt"><strong><span style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 'Courier New'">                @FinalLength  </span></strong><strong><span style="FONT-SIZE: 10pt; COLOR: blue; FONT-FAMILY: 'Courier New'">INT</span></strong><strong><span style="FONT-SIZE: 10pt; COLOR: navy; FONT-FAMILY: 'Courier New'">,</span></strong><strong><span style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 'Courier New'"> </span></strong><strong><span style="FONT-SIZE: 11pt; COLOR: black; FONT-FAMILY: Calibri"></span></strong></p>
<p class="MsoNormal" style="MARGIN: 0in 0in 0pt"><strong><span style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 'Courier New'">                @PadChar      </span></strong><strong><span style="FONT-SIZE: 10pt; COLOR: blue; FONT-FAMILY: 'Courier New'">CHAR</span></strong><strong><span style="FONT-SIZE: 10pt; COLOR: navy; FONT-FAMILY: 'Courier New'">(</span></strong><strong><span style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 'Courier New'">1</span></strong><strong><span style="FONT-SIZE: 10pt; COLOR: navy; FONT-FAMILY: 'Courier New'">))</span></strong><strong><span style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 'Courier New'"> </span></strong><strong><span style="FONT-SIZE: 11pt; COLOR: black; FONT-FAMILY: Calibri"></span></strong></p>
<p class="MsoNormal" style="MARGIN: 0in 0in 0pt"><strong><span style="FONT-SIZE: 10pt; COLOR: blue; FONT-FAMILY: 'Courier New'">RETURNS</span></strong><strong><span style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 'Courier New'"> </span></strong><strong><span style="FONT-SIZE: 10pt; COLOR: blue; FONT-FAMILY: 'Courier New'">VARCHAR</span></strong><strong><span style="FONT-SIZE: 10pt; COLOR: navy; FONT-FAMILY: 'Courier New'">(</span></strong><strong><span style="FONT-SIZE: 10pt; COLOR: fuchsia; FONT-FAMILY: 'Courier New'">MAX</span></strong><strong><span style="FONT-SIZE: 10pt; COLOR: navy; FONT-FAMILY: 'Courier New'">)</span></strong><strong><span style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 'Courier New'"> </span></strong><strong><span style="FONT-SIZE: 11pt; COLOR: black; FONT-FAMILY: Calibri"></span></strong></p>
<p class="MsoNormal" style="MARGIN: 0in 0in 0pt"><strong><span style="FONT-SIZE: 10pt; COLOR: blue; FONT-FAMILY: 'Courier New'">AS</span></strong><strong><span style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 'Courier New'"> </span></strong><strong><span style="FONT-SIZE: 11pt; COLOR: black; FONT-FAMILY: Calibri"></span></strong></p>
<p class="MsoNormal" style="MARGIN: 0in 0in 0pt"><strong><span style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 'Courier New'">  </span></strong><strong><span style="FONT-SIZE: 10pt; COLOR: blue; FONT-FAMILY: 'Courier New'">BEGIN</span></strong><strong><span style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 'Courier New'"> </span></strong><strong><span style="FONT-SIZE: 11pt; COLOR: black; FONT-FAMILY: Calibri"></span></strong></p>
<p class="MsoNormal" style="MARGIN: 0in 0in 0pt"><strong><span style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 'Courier New'">    </span></strong><strong><span style="FONT-SIZE: 10pt; COLOR: blue; FONT-FAMILY: 'Courier New'">RETURN</span></strong><strong><span style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 'Courier New'"> </span></strong><strong><span style="FONT-SIZE: 11pt; COLOR: black; FONT-FAMILY: Calibri"></span></strong></p>
<p class="MsoNormal" style="MARGIN: 0in 0in 0pt"><strong><span style="FONT-SIZE: 10pt; COLOR: blue; FONT-FAMILY: 'Courier New'">      </span></strong><strong><span style="FONT-SIZE: 10pt; COLOR: navy; FONT-FAMILY: 'Courier New'">(</span></strong><strong><span style="FONT-SIZE: 10pt; COLOR: blue; FONT-FAMILY: 'Courier New'">SELECT</span></strong><strong><span style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 'Courier New'"> @SourceString </span></strong><strong><span style="FONT-SIZE: 10pt; COLOR: navy; FONT-FAMILY: 'Courier New'">+</span></strong><strong><span style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 'Courier New'"> </span></strong><strong><span style="FONT-SIZE: 10pt; COLOR: fuchsia; FONT-FAMILY: 'Courier New'">Replicate</span></strong><strong><span style="FONT-SIZE: 10pt; COLOR: navy; FONT-FAMILY: 'Courier New'">(</span></strong><strong><span style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 'Courier New'">@PadChar</span></strong><strong><span style="FONT-SIZE: 10pt; COLOR: navy; FONT-FAMILY: 'Courier New'">,</span></strong><strong><span style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 'Courier New'">@FinalLength </span></strong><strong><span style="FONT-SIZE: 10pt; COLOR: navy; FONT-FAMILY: 'Courier New'">-</span></strong><strong><span style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 'Courier New'"> </span></strong><strong><span style="FONT-SIZE: 10pt; COLOR: fuchsia; FONT-FAMILY: 'Courier New'">Len</span></strong><strong><span style="FONT-SIZE: 10pt; COLOR: navy; FONT-FAMILY: 'Courier New'">(</span></strong><strong><span style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 'Courier New'">@SourceString</span></strong><strong><span style="FONT-SIZE: 10pt; COLOR: navy; FONT-FAMILY: 'Courier New'">)))</span></strong><strong><span style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 'Courier New'"> </span></strong><strong><span style="FONT-SIZE: 11pt; COLOR: black; FONT-FAMILY: Calibri"></span></strong></p>
<p class="MsoNormal" style="MARGIN: 0in 0in 0pt"><strong><span style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 'Courier New'">  </span></strong><strong><span style="FONT-SIZE: 10pt; COLOR: blue; FONT-FAMILY: 'Courier New'">END</span></strong><strong><span style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 'Courier New'"> </span></strong><strong><span style="FONT-SIZE: 11pt; COLOR: black; FONT-FAMILY: Calibri"></span></strong></p>
<p class="MsoNormal" style="MARGIN: 0in 0in 0pt"><strong><span style="FONT-SIZE: 10pt; COLOR: blue; FONT-FAMILY: 'Courier New'">GO</code></span></strong><strong><span style="FONT-SIZE: 11pt; COLOR: black; FONT-FAMILY: Calibri"></span></strong></p>
<p> </p>
<p> In the example above, you would accomplish this like so:</p>
<p><code>EXEC <strong><span style="font-size: 10pt; font-family: &quot;Courier New&quot;;">dbo<span style="color: navy;">.</span>LPAD<span style="color: navy;">(</span><span style="color: fuchsia;">Cast</span><span style="color: navy;">(123</span> <span style="color: blue;">AS</span> <span style="color: blue;">VARCHAR</span><span style="color: navy;">),6</span><span style="color: navy;">,</span><span style="color: red;">'0'</span><span style="color: navy;">)</code></span></span></strong><br />
<strong><span style="font-size: 10pt; font-family: &quot;Courier New&quot;;"><span style="color: navy;">OR</span></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt;"><strong><span style="font-size: 10pt; color: blue; font-family: &quot;Courier New&quot;;"><code>SELECT</span></strong><strong><span style="font-size: 10pt; font-family: &quot;Courier New&quot;;"><span style="color: #000000;"> NewString </span><span style="color: navy;">=</span><span style="color: #000000;"> dbo</span><span style="color: navy;">.</span><span style="color: #000000;">LPAD</span><span style="color: navy;">(</span><span style="color: fuchsia;">Cast</span><span style="color: navy;">(</span><span style="color: #000000;">123 </span><span style="color: blue;">AS</span><span style="color: #000000;"> </span><span style="color: blue;">VARCHAR</span><span style="color: navy;">),</span><span style="color: #000000;">6</span><span style="color: navy;">,</span><span style="color: red;">'0'</span><span style="color: navy;">)</code></span></span></strong></p>
<p></strong>Here&#8217;s where I found it.  <a href="http://www.sqlusa.com/bestpractices2005/padleadingzeros/">http://www.sqlusa.com/bestpractices2005/padleadingzeros/</a></p>
]]></content:encoded>
			<wfw:commentRss>http://rickcaminiti.com/tips/rpad-lpad-equivalent-tsql/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Obscure Timestamp DataType in SQL</title>
		<link>http://rickcaminiti.com/misc/obscure-timestamp-datatype-sql/</link>
		<comments>http://rickcaminiti.com/misc/obscure-timestamp-datatype-sql/#comments</comments>
		<pubDate>Mon, 15 Jun 2009 21:20:42 +0000</pubDate>
		<dc:creator>NothingMan</dc:creator>
				<category><![CDATA[BI]]></category>
		<category><![CDATA[Code]]></category>
		<category><![CDATA[Misc]]></category>
		<category><![CDATA[Tips]]></category>

		<guid isPermaLink="false">http://rickcaminiti.com/?p=378</guid>
		<description>In SQL Server, a Timestamp field helps to keep track of changes to a table in a Database. To use it, you simply define a field without a name, and a data type of TIMESTAMP. SQL Server automatically inserts an internal identifier into the column whenever a row is inserted or updated. To get the [...]</description>
			<content:encoded><![CDATA[<p class="MsoNormal" style="margin: 0in 0in 0pt;"><span style="font-size: small; font-family: Times New Roman;">In SQL Server, a Timestamp field helps to keep track of changes to a table in a Database.<br />
To use it, you simply define a field without a name, and a data type of TIMESTAMP.<br />
SQL Server automatically inserts an internal identifier into the column whenever a row is inserted or updated. To get the current value use ‘SELECT @@DBTS.</span><br />
<code></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; color: blue; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"> </span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; color: blue; font-family: &quot;Courier New&quot;; mso-no-proof: yes;">CREATE</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"> TABLE <span style="color: gray;">.</span>t2</span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-tab-count: 1;">      </span><span style="color: gray;">(</span></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-tab-count: 1;">      </span>a <span style="color: blue;">int</span> <span style="color: gray;">NULL,</span></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-tab-count: 1;">      </span>b <span style="color: blue;">int</span> <span style="color: gray;">NULL,</span></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-tab-count: 1;">      </span><span style="color: blue;">timestamp</span> <span style="color: gray;">NULL</span></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-tab-count: 1;">      </span><span style="color: gray;">)</span><span style="mso-spacerun: yes;">  </span><span style="color: blue;">ON</span> [PRIMARY]</span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;">GO</span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; color: blue; font-family: &quot;Courier New&quot;; mso-no-proof: yes;">COMMIT</span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; color: blue; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"> </span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; color: blue; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"> </span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; color: blue; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"> </span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; color: blue; font-family: &quot;Courier New&quot;; mso-no-proof: yes;">insert</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"> <span style="color: blue;">into</span> t</span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; color: gray; font-family: &quot;Courier New&quot;; mso-no-proof: yes;">(</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;">a<span style="color: gray;">,</span> b<span style="color: gray;">)</span></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; color: blue; font-family: &quot;Courier New&quot;; mso-no-proof: yes;">values</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"> <span style="color: gray;">(</span>1<span style="color: gray;">,</span> 2<span style="color: gray;">)</span></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; color: gray; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"> </span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; color: blue; font-family: &quot;Courier New&quot;; mso-no-proof: yes;">SELECT</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"> <span style="color: fuchsia;">@@DBTS</span> DBTS</span></p>
<table class="MsoNormalTable" style="margin: auto auto auto 4.65pt; width: 103pt; border-collapse: collapse; mso-padding-alt: 0in 5.4pt 0in 5.4pt;" border="0" cellspacing="0" cellpadding="0" width="137">
<tbody>
<tr style="height: 12.75pt; mso-yfti-irow: 0; mso-yfti-firstrow: yes;">
<td style="padding-right: 5.4pt; padding-left: 5.4pt; padding-bottom: 0in; width: 103pt; padding-top: 0in; height: 12.75pt; background-color: transparent; border: #ece9d8;" width="137" valign="bottom">
<p class="MsoNormal" style="margin: 0in 0in 0pt;"><strong><span style="font-size: 10pt; font-family: Arial;">DBTS</span></strong></p>
</td>
</tr>
<tr style="height: 12.75pt; mso-yfti-irow: 1; mso-yfti-lastrow: yes;">
<td style="padding-right: 5.4pt; padding-left: 5.4pt; padding-bottom: 0in; width: 103pt; padding-top: 0in; height: 12.75pt; background-color: transparent; border: #ece9d8;" width="137" valign="bottom">
<p class="MsoNormal" style="margin: 0in 0in 0pt;"><span style="font-size: 10pt; font-family: Arial;">0x00000000000007E6</span></p>
</td>
</tr>
</tbody>
</table>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"> </span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"> </span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; color: blue; font-family: &quot;Courier New&quot;; mso-no-proof: yes;">select</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"> <span style="color: gray;">*</span> <span style="color: blue;">from</span> t</span></p>
<table class="MsoNormalTable" style="margin: auto auto auto 4.65pt; width: 151pt; border-collapse: collapse; mso-padding-alt: 0in 5.4pt 0in 5.4pt;" border="0" cellspacing="0" cellpadding="0" width="201">
<tbody>
<tr style="height: 12.75pt; mso-yfti-irow: 0; mso-yfti-firstrow: yes;">
<td style="padding-right: 5.4pt; padding-left: 5.4pt; padding-bottom: 0in; width: 22pt; padding-top: 0in; height: 12.75pt; background-color: transparent; border: #ece9d8;" width="29" valign="bottom">
<p class="MsoNormal" style="margin: 0in 0in 0pt;"><span style="font-size: 10pt; font-family: Arial;">a</span></p>
</td>
<td style="padding-right: 5.4pt; padding-left: 5.4pt; padding-bottom: 0in; width: 26pt; padding-top: 0in; height: 12.75pt; background-color: transparent; border: #ece9d8;" width="35" valign="bottom">
<p class="MsoNormal" style="margin: 0in 0in 0pt;"><span style="font-size: 10pt; font-family: Arial;">b</span></p>
</td>
<td style="padding-right: 5.4pt; padding-left: 5.4pt; padding-bottom: 0in; width: 103pt; padding-top: 0in; height: 12.75pt; background-color: transparent; border: #ece9d8;" width="137" valign="bottom">
<p class="MsoNormal" style="margin: 0in 0in 0pt;"><span style="font-size: 10pt; font-family: Arial;">timestamp</span></p>
</td>
</tr>
<tr style="height: 12.75pt; mso-yfti-irow: 1;">
<td style="padding-right: 5.4pt; padding-left: 5.4pt; padding-bottom: 0in; width: 22pt; padding-top: 0in; height: 12.75pt; background-color: transparent; border: #ece9d8;" width="29" valign="bottom">
<p class="MsoNormal" style="margin: 0in 0in 0pt; text-align: right;" align="right"><span style="font-size: 10pt; font-family: Arial;">1</span></p>
</td>
<td style="padding-right: 5.4pt; padding-left: 5.4pt; padding-bottom: 0in; width: 26pt; padding-top: 0in; height: 12.75pt; background-color: transparent; border: #ece9d8;" width="35" valign="bottom">
<p class="MsoNormal" style="margin: 0in 0in 0pt; text-align: right;" align="right"><span style="font-size: 10pt; font-family: Arial;">2</span></p>
</td>
<td style="padding-right: 5.4pt; padding-left: 5.4pt; padding-bottom: 0in; width: 103pt; padding-top: 0in; height: 12.75pt; background-color: transparent; border: #ece9d8;" width="137" valign="bottom">
<p class="MsoNormal" style="margin: 0in 0in 0pt;"><span style="font-size: 10pt; font-family: Arial;">0x00000000000007E2</span></p>
</td>
</tr>
<tr style="height: 12.75pt; mso-yfti-irow: 2;">
<td style="padding-right: 5.4pt; padding-left: 5.4pt; padding-bottom: 0in; width: 22pt; padding-top: 0in; height: 12.75pt; background-color: transparent; border: #ece9d8;" width="29" valign="bottom">
<p class="MsoNormal" style="margin: 0in 0in 0pt; text-align: right;" align="right"><span style="font-size: 10pt; font-family: Arial;">1</span></p>
</td>
<td style="padding-right: 5.4pt; padding-left: 5.4pt; padding-bottom: 0in; width: 26pt; padding-top: 0in; height: 12.75pt; background-color: transparent; border: #ece9d8;" width="35" valign="bottom">
<p class="MsoNormal" style="margin: 0in 0in 0pt; text-align: right;" align="right"><span style="font-size: 10pt; font-family: Arial;">2</span></p>
</td>
<td style="padding-right: 5.4pt; padding-left: 5.4pt; padding-bottom: 0in; width: 103pt; padding-top: 0in; height: 12.75pt; background-color: transparent; border: #ece9d8;" width="137" valign="bottom">
<p class="MsoNormal" style="margin: 0in 0in 0pt;"><span style="font-size: 10pt; font-family: Arial;">0x00000000000007E3</span></p>
</td>
</tr>
<tr style="height: 12.75pt; mso-yfti-irow: 3;">
<td style="padding-right: 5.4pt; padding-left: 5.4pt; padding-bottom: 0in; width: 22pt; padding-top: 0in; height: 12.75pt; background-color: transparent; border: #ece9d8;" width="29" valign="bottom">
<p class="MsoNormal" style="margin: 0in 0in 0pt; text-align: right;" align="right"><span style="font-size: 10pt; font-family: Arial;">1</span></p>
</td>
<td style="padding-right: 5.4pt; padding-left: 5.4pt; padding-bottom: 0in; width: 26pt; padding-top: 0in; height: 12.75pt; background-color: transparent; border: #ece9d8;" width="35" valign="bottom">
<p class="MsoNormal" style="margin: 0in 0in 0pt; text-align: right;" align="right"><span style="font-size: 10pt; font-family: Arial;">2</span></p>
</td>
<td style="padding-right: 5.4pt; padding-left: 5.4pt; padding-bottom: 0in; width: 103pt; padding-top: 0in; height: 12.75pt; background-color: transparent; border: #ece9d8;" width="137" valign="bottom">
<p class="MsoNormal" style="margin: 0in 0in 0pt;"><span style="font-size: 10pt; font-family: Arial;">0x00000000000007E4</span></p>
</td>
</tr>
<tr style="height: 12.75pt; mso-yfti-irow: 4;">
<td style="padding-right: 5.4pt; padding-left: 5.4pt; padding-bottom: 0in; width: 22pt; padding-top: 0in; height: 12.75pt; background-color: transparent; border: #ece9d8;" width="29" valign="bottom">
<p class="MsoNormal" style="margin: 0in 0in 0pt; text-align: right;" align="right"><span style="font-size: 10pt; font-family: Arial;">1</span></p>
</td>
<td style="padding-right: 5.4pt; padding-left: 5.4pt; padding-bottom: 0in; width: 26pt; padding-top: 0in; height: 12.75pt; background-color: transparent; border: #ece9d8;" width="35" valign="bottom">
<p class="MsoNormal" style="margin: 0in 0in 0pt; text-align: right;" align="right"><span style="font-size: 10pt; font-family: Arial;">2</span></p>
</td>
<td style="padding-right: 5.4pt; padding-left: 5.4pt; padding-bottom: 0in; width: 103pt; padding-top: 0in; height: 12.75pt; background-color: transparent; border: #ece9d8;" width="137" valign="bottom">
<p class="MsoNormal" style="margin: 0in 0in 0pt;"><span style="font-size: 10pt; font-family: Arial;">0x00000000000007E5</span></p>
</td>
</tr>
<tr style="height: 12.75pt; mso-yfti-irow: 5; mso-yfti-lastrow: yes;">
<td style="padding-right: 5.4pt; padding-left: 5.4pt; padding-bottom: 0in; width: 22pt; padding-top: 0in; height: 12.75pt; background-color: transparent; border: #ece9d8;" width="29" valign="bottom">
<p class="MsoNormal" style="margin: 0in 0in 0pt; text-align: right;" align="right"><span style="font-size: 10pt; font-family: Arial;">1</span></p>
</td>
<td style="padding-right: 5.4pt; padding-left: 5.4pt; padding-bottom: 0in; width: 26pt; padding-top: 0in; height: 12.75pt; background-color: transparent; border: #ece9d8;" width="35" valign="bottom">
<p class="MsoNormal" style="margin: 0in 0in 0pt; text-align: right;" align="right"><span style="font-size: 10pt; font-family: Arial;">2</span></p>
</td>
<td style="padding-right: 5.4pt; padding-left: 5.4pt; padding-bottom: 0in; width: 103pt; padding-top: 0in; height: 12.75pt; background-color: transparent; border: #ece9d8;" width="137" valign="bottom">
<p class="MsoNormal" style="margin: 0in 0in 0pt;"><span style="font-size: 10pt; font-family: Arial;">0x00000000000007E6</span></p>
</td>
</tr>
</tbody>
</table>
<p class="MsoNormal" style="margin: 0in 0in 0pt;"><span style="font-size: small; font-family: Times New Roman;"> </span></p>
<p></code></p>
]]></content:encoded>
			<wfw:commentRss>http://rickcaminiti.com/misc/obscure-timestamp-datatype-sql/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>User Defined IsNumeric Function in PL/SQL</title>
		<link>http://rickcaminiti.com/tips/user-defined-isnumeric-function-plsql/</link>
		<comments>http://rickcaminiti.com/tips/user-defined-isnumeric-function-plsql/#comments</comments>
		<pubDate>Sun, 14 Jun 2009 20:48:28 +0000</pubDate>
		<dc:creator>NothingMan</dc:creator>
				<category><![CDATA[BI]]></category>
		<category><![CDATA[Code]]></category>
		<category><![CDATA[Tips]]></category>
		<category><![CDATA[oracle]]></category>
		<category><![CDATA[pl/sql]]></category>
		<category><![CDATA[sql]]></category>
		<category><![CDATA[udf]]></category>

		<guid isPermaLink="false">http://rickcaminiti.com/?p=374</guid>
		<description>Short and sweet. Accept a varchar input parameter, try to convert it to a number. If the conversion fails for any reason, return FALSE, else, return TRUE. CREATE OR REPLACE FUNCTION is_numeric (    p_data   VARCHAR2 )    RETURN NUMBER IS    v_number   NUMBER;    o_bool     BOOLEAN := TRUE; BEGIN    BEGIN       v_number := [...]</description>
			<content:encoded><![CDATA[<p>Short and sweet.  Accept a varchar input parameter, try to convert it to a number.  If the conversion fails for any reason, return FALSE, else, return TRUE.</p>
<p><code>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; color: blue; font-family: &quot;Courier New&quot;; mso-no-proof: yes;">CREATE</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"> <span style="color: gray;">OR</span> <span style="color: fuchsia;">REPLACE</span> <span style="color: blue;">FUNCTION</span> is_numeric <span style="color: gray;">(</span></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;">   </span>p_data<span style="mso-spacerun: yes;">   </span>VARCHAR2</span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; color: gray; font-family: &quot;Courier New&quot;; mso-no-proof: yes;">)</span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;">   </span><span style="color: blue;">RETURN</span> NUMBER </span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; color: gray; font-family: &quot;Courier New&quot;; mso-no-proof: yes;">IS</span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;">   </span>v_number<span style="mso-spacerun: yes;">   </span>NUMBER<span style="color: gray;">;</span></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;">   </span>o_bool<span style="mso-spacerun: yes;">     </span>BOOLEAN <span style="color: gray;">:=</span> TRUE<span style="color: gray;">;</span></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; color: blue; font-family: &quot;Courier New&quot;; mso-no-proof: yes;">BEGIN</span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;">   </span><span style="color: blue;">BEGIN</span></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;">      </span>v_number <span style="color: gray;">:=</span> p_data<span style="color: gray;">;</span></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;">   </span>EXCEPTION</span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;">      </span><span style="color: blue;">WHEN</span> OTHERS <span style="color: blue;">THEN</span></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;">         </span>o_bool <span style="color: gray;">:=</span> FALSE<span style="color: gray;">;</span></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;">   </span><span style="color: blue;">END</span><span style="color: gray;">;</span></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; color: gray; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"> </span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;">   </span><span style="color: blue;">RETURN</span> o_bool<span style="color: gray;">;</span></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt;"><span style="font-size: 10pt; color: blue; font-family: &quot;Courier New&quot;; mso-no-proof: yes;">END</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"> isnumber<span style="color: gray;">;</span></span></p>
<p></code></p>
]]></content:encoded>
			<wfw:commentRss>http://rickcaminiti.com/tips/user-defined-isnumeric-function-plsql/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Quick Reference to SQL Server Date Formats</title>
		<link>http://rickcaminiti.com/tips/quick-reference-sql-server-date-formats/</link>
		<comments>http://rickcaminiti.com/tips/quick-reference-sql-server-date-formats/#comments</comments>
		<pubDate>Sat, 13 Jun 2009 20:36:27 +0000</pubDate>
		<dc:creator>NothingMan</dc:creator>
				<category><![CDATA[BI]]></category>
		<category><![CDATA[Code]]></category>
		<category><![CDATA[Tips]]></category>

		<guid isPermaLink="false">http://rickcaminiti.com/?p=370</guid>
		<description>Just stumbled upon this site that has a great list of common SQL Server date formats. It&amp;#8217;s never easy in SQL to format dates, but with this list, it should be simple. This also includes 3 simple ways to get JUST the date portion of a datetime field. When you&amp;#8217;re just starting with SQL, this [...]</description>
			<content:encoded><![CDATA[<p>Just stumbled upon this site that has a great list of common SQL Server date formats.  It&#8217;s never easy in SQL to format dates, but with this list, it should be simple.</p>
<p>This also includes 3 simple ways to get JUST the date portion of a datetime field.  When you&#8217;re just starting with SQL, this is about the most common question.</p>
<p><code><br />
CAST(CONVERT(VARCHAR(10), @pInputDate, 111) AS DATETIME)<br />
</code><br />
<code><br />
CAST(CAST(YEAR(@pInputDate) AS VARCHAR(4)) + '/' +<br />
CAST(MONTH(@pInputDate) AS VARCHAR(2)) + '/' +<br />
CAST(DAY(@pInputDate) AS VARCHAR(2)) AS DATETIME)<br />
</code><br />
<code><br />
CAST(FLOOR(CAST(@pInputDate AS DECIMAL(12, 5))) AS DATETIME)<br />
</code></p>
<p>http://www.sql-server-helper.com/tips/date-formats.aspx</p>
]]></content:encoded>
			<wfw:commentRss>http://rickcaminiti.com/tips/quick-reference-sql-server-date-formats/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Short-Circuiting in C# with OrElse Operator</title>
		<link>http://rickcaminiti.com/tips/shortcircuiting-orelse-operator/</link>
		<comments>http://rickcaminiti.com/tips/shortcircuiting-orelse-operator/#comments</comments>
		<pubDate>Fri, 12 Jun 2009 20:33:07 +0000</pubDate>
		<dc:creator>NothingMan</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[Tips]]></category>
		<category><![CDATA[g33k]]></category>

		<guid isPermaLink="false">http://rickcaminiti.com/?p=366</guid>
		<description>I&amp;#8217;d heard about short-circuiting before but had never seen it actually applied.  I guess the main benefit of the OrElse operator is that it can improve performance if the &amp;#8220;bypassed&amp;#8221; condition is cumbersome.  It&amp;#8217;s basically an OR statement, but if the first expression evaluates as TRUE, it doesn&amp;#8217;t need to evaluate the second expression.  Normally, [...]</description>
			<content:encoded><![CDATA[<p>I&#8217;d heard about short-circuiting before but had never seen it actually applied.  I guess the main benefit of the OrElse operator is that it can improve performance if the &#8220;bypassed&#8221; condition is cumbersome.  It&#8217;s basically an OR statement, but if the first expression evaluates as TRUE, it doesn&#8217;t need to evaluate the second expression.  Normally, both expressions would be evaulated, but in reality, if the first one is TRUE, the whole condition is TRUE, so why evaluate the second one, right?</p>
<p><code>
<dt><em>result</em> </dt>
<dd>Required. Any <strong>Boolean</strong> expression. </dd>
<dt><em>expression1</em> </dt>
<dd>Required. Any <strong>Boolean</strong> expression. </dd>
<dt><em>expression2</em> </dt>
<dd>Required. Any <strong>Boolean</strong> expression. </dd>
<dd></dd>
<p></code></p>
<table border="0">
<tbody>
<tr valign="top">
<th width="26%">If <em>expression1</em> is</th>
<th width="30%">And <em>expression2</em> is</th>
<th width="44%">Then <em>result</em> is</th>
</tr>
<tr valign="top">
<td width="26%"><strong>True</strong></td>
<td width="30%">(not evaluated)</td>
<td width="44%"><strong>True</strong></td>
</tr>
<tr valign="top">
<td width="26%"><strong>False</strong></td>
<td width="30%"><strong>True</strong></td>
<td width="44%"><strong>True</strong></td>
</tr>
<tr valign="top">
<td width="26%"><strong>False</strong></td>
<td width="30%"><strong>False</strong></td>
<td width="44%"><strong>False</strong></td>
</tr>
</tbody>
</table>
<p>It&#8217;s this simple:</p>
<p><code>Dim A As Integer = 10<br />
Dim B As Integer = 8<br />
Dim C As Integer = 6<br />
Dim myCheck As Boolean<br />
myCheck = A &gt; B OrElse B &gt; C   ' True. Second expression is not evaluated.<br />
myCheck = B &gt; A OrElse B &gt; C   ' True. Second expression is evaluated.<br />
myCheck = B &gt; A OrElse C &gt; B   ' False.</p>
<p>If MyFunction(5) = True OrElse MyOtherFunction(4) = True Then<br />
' If MyFunction(5) is True, MyOtherFunction(4) is not called.<br />
   ' Insert code to be executed.<br />
End If</code></p>
]]></content:encoded>
			<wfw:commentRss>http://rickcaminiti.com/tips/shortcircuiting-orelse-operator/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Alternative, Efficient Way to Get Table’s RowCount in SQL</title>
		<link>http://rickcaminiti.com/tips/alternative-efficient-tables-rowcount-sql/</link>
		<comments>http://rickcaminiti.com/tips/alternative-efficient-tables-rowcount-sql/#comments</comments>
		<pubDate>Fri, 12 Jun 2009 00:49:35 +0000</pubDate>
		<dc:creator>NothingMan</dc:creator>
				<category><![CDATA[BI]]></category>
		<category><![CDATA[Code]]></category>
		<category><![CDATA[Tips]]></category>
		<category><![CDATA[mssql]]></category>
		<category><![CDATA[sql]]></category>
		<category><![CDATA[stats]]></category>
		<category><![CDATA[tuning]]></category>

		<guid isPermaLink="false">http://rickcaminiti.com/?p=355</guid>
		<description>I found this post about a more efficient way to get the table rowcount from a given table. SELECT COUNT(*) statements make a full table scans to return the total table&amp;#8217;s row count, it can take a lot of time and a lot of &amp;#8220;energy&amp;#8221; for a large table. There is another way to determine [...]</description>
			<content:encoded><![CDATA[<p>I found this <a title="Alternative way to get the table's row count" href="http://www.mssqlcity.com/Tips/tipTSQL.htm" target="_blank">post </a>about a more efficient way to get the table rowcount from a given table.</p>
<p>SELECT COUNT(*) statements make a full table scans to return the total table&#8217;s row count, it can take a lot of time and a lot of &#8220;energy&#8221; for a large table.</p>
<p>There is another way to determine the total row count in a table by using the sysindexes system table. There is a column (ROWS) in it that contains the total row count for each table in your database.</p>
<p>You can use the syntax below to speed up the query by several times.  You can see this by setting statistics on, as shown below.</p>
<div></div>
<p><code></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; color: blue; font-family: &quot;Courier New&quot;; mso-no-proof: yes;">SET</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"> <span style="color: blue;">STATISTICS</span> <span style="color: blue;">IO</span> <span style="color: blue;">ON<br />
</span></span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;">GO</span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; color: blue; font-family: &quot;Courier New&quot;; mso-no-proof: yes;">SELECT</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"> <span style="color: fuchsia;">count</span><span style="color: gray;">(*)</span> <span style="color: blue;">FROM</span> tbTest<br />
</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;">GO</span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; color: blue; font-family: &quot;Courier New&quot;; mso-no-proof: yes;">SELECT</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"> <span style="color: blue;">rows</span> <span style="color: blue;">FROM</span> sysindexes <span style="color: blue;">WHERE</span> id <span style="color: gray;">=</span> <span style="color: fuchsia;">OBJECT_ID</span><span style="color: gray;">(</span><span style="color: red;">'tbTest'</span><span style="color: gray;">)</span> <span style="color: gray;">AND</span> indid <span style="color: gray;">&lt;</span> 2<br />
</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;">GO</span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; color: blue; font-family: &quot;Courier New&quot;; mso-no-proof: yes;">SET</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"> <span style="color: blue;">STATISTICS</span> <span style="color: blue;">IO</span> <span style="color: blue;">OFF<br />
</span></span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;">GO</span></p>
<p> </p>
<p> </p>
<p></code></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<div class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;">&#8212;&#8212;&#8212;&#8211;<br />
10000</span></div>
<div><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;">(1 row(s) affected)</span></div>
<p><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;">Table &#8216;tbTest&#8217;. Scan count 1, logical reads 32, physical reads 0, read-ahead reads 0.<br />
rows       <br />
&#8212;&#8212;&#8212;&#8211;<br />
10000</p>
<p>(1 row(s) affected)</p>
<p>Table &#8216;sysindexes&#8217;. Scan count 1, logical reads 2, physical reads 0, read-ahead reads 0.</p>
<p> </p>
<p></span></p>
]]></content:encoded>
			<wfw:commentRss>http://rickcaminiti.com/tips/alternative-efficient-tables-rowcount-sql/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>SQL Server Computed Column</title>
		<link>http://rickcaminiti.com/tips/sql-server-computed-column/</link>
		<comments>http://rickcaminiti.com/tips/sql-server-computed-column/#comments</comments>
		<pubDate>Wed, 10 Jun 2009 15:36:20 +0000</pubDate>
		<dc:creator>NothingMan</dc:creator>
				<category><![CDATA[BI]]></category>
		<category><![CDATA[Code]]></category>
		<category><![CDATA[Tips]]></category>
		<category><![CDATA[column]]></category>
		<category><![CDATA[cool]]></category>
		<category><![CDATA[mssql]]></category>
		<category><![CDATA[sql]]></category>
		<category><![CDATA[t-sql]]></category>
		<category><![CDATA[table]]></category>
		<category><![CDATA[tip]]></category>

		<guid isPermaLink="false">http://rickcaminiti.com/?p=353</guid>
		<description>I always thought the only way to have a computed or derived column in SQL was to use some kind of a view in place, but I found out that you can actually create a computed column on a table and that you can even &amp;#8220;persist&amp;#8221; the data and have it indexed. I&amp;#8217;m only guessing [...]</description>
			<content:encoded><![CDATA[<p>I always thought the only way to have a computed or derived column in SQL was to use some kind of a view in place, but I found out that you can actually create a computed column on a table and that you can even &#8220;persist&#8221; the data and have it indexed.</p>
<p>I&#8217;m only guessing that behind the scenes, SQL treats this somewhat like a trigger, like a before-trigger, where just prior to the transaction being posted, the calculations are applied and the column is populated, then the full transaction is applied.</p>
<p>Here&#8217;s the article where I found this <a href="http://msdn.microsoft.com/en-us/library/ms189292.aspx">information</a>.</p>
<p>And here&#8217;s an example:<br />
<code></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; color: blue; font-family: &quot;Courier New&quot;; mso-no-proof: yes;">use</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"> <span style="color: blue;">database</span> </span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"> </span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; color: blue; font-family: &quot;Courier New&quot;; mso-no-proof: yes;">create</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"> <span style="color: blue;">table</span> t </span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; color: gray; font-family: &quot;Courier New&quot;; mso-no-proof: yes;">(</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"> a <span style="color: blue;">int</span><span style="color: gray;">,</span> b <span style="color: blue;">int</span><span style="color: gray;">);</span> </span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"> </span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; color: green; font-family: &quot;Courier New&quot;; mso-no-proof: yes;">--adding the computed column</span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; color: blue; font-family: &quot;Courier New&quot;; mso-no-proof: yes;">alter</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"> <span style="color: blue;">table</span> t <span style="color: blue;">add</span> </span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;">x <span style="color: blue;">as</span> <span style="color: blue;">case</span> a<span style="mso-spacerun: yes;">  </span></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-tab-count: 2;">            </span><span style="color: blue;">when</span> <span style="color: gray;">-</span>1 <span style="color: blue;">then</span> </span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-tab-count: 3;">                  </span>b </span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-tab-count: 2;">            </span><span style="color: blue;">else</span> </span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-tab-count: 3;">                  </span>a </span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-tab-count: 2;">            </span><span style="color: blue;">end</span> <span style="color: blue;">persisted</span> <span style="color: gray;">not</span> <span style="color: gray;">null</span></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; color: green; font-family: &quot;Courier New&quot;; mso-no-proof: yes;">--using "persisted" is required if you want to make column "not null".<span style="mso-spacerun: yes;">  </span>I believe "persisted" is somewhat implied if computed column is derived from PK columns.</span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; color: green; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"> </span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; color: green; font-family: &quot;Courier New&quot;; mso-no-proof: yes;">--just showing that you can create an index on the new column</span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; color: blue; font-family: &quot;Courier New&quot;; mso-no-proof: yes;">create</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"> <span style="color: blue;">index</span> z <span style="color: blue;">on</span> t <span style="color: gray;">(</span>x<span style="color: gray;">)</span> </span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"> </span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"> </span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; color: blue; font-family: &quot;Courier New&quot;; mso-no-proof: yes;">insert</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"> <span style="color: blue;">into</span> t <span style="color: blue;">values</span> <span style="color: gray;">(</span>1<span style="color: gray;">,</span> <span style="color: gray;">-</span>1<span style="color: gray;">)</span> </span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; color: blue; font-family: &quot;Courier New&quot;; mso-no-proof: yes;">insert</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"> <span style="color: blue;">into</span> t <span style="color: blue;">values</span> <span style="color: gray;">(</span>2<span style="color: gray;">,</span> <span style="color: gray;">-</span>1<span style="color: gray;">)</span> </span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; color: blue; font-family: &quot;Courier New&quot;; mso-no-proof: yes;">insert</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"> <span style="color: blue;">into</span> t <span style="color: blue;">values</span> <span style="color: gray;">(-</span>1<span style="color: gray;">,</span> 4<span style="color: gray;">)</span> </span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; color: blue; font-family: &quot;Courier New&quot;; mso-no-proof: yes;">insert</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"> <span style="color: blue;">into</span> t <span style="color: blue;">values</span> <span style="color: gray;">(-</span>1<span style="color: gray;">,</span> 3<span style="color: gray;">)</span> </span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; color: blue; font-family: &quot;Courier New&quot;; mso-no-proof: yes;">insert</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"> <span style="color: blue;">into</span> t <span style="color: blue;">values</span> <span style="color: gray;">(-</span>1<span style="color: gray;">,</span> <span style="color: gray;">-</span>1<span style="color: gray;">)</span> </span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"> </span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; color: blue; font-family: &quot;Courier New&quot;; mso-no-proof: yes;">select</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"> <span style="color: gray;">*</span> <span style="color: blue;">from</span> t </span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"> </span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"> </span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"> </span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; color: green; font-family: &quot;Courier New&quot;; mso-no-proof: yes;">--you can see that the computed column worked.</span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><strong>a<span style="mso-spacerun: yes;">       </span>b<span style="mso-spacerun: yes;">       </span>x</strong><span style="mso-spacerun: yes;">      </span></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;">1<span style="mso-spacerun: yes;">       </span><span style="color: gray;">-</span>1<span style="mso-spacerun: yes;">      </span>1<span style="mso-spacerun: yes;">      </span></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;">2<span style="mso-spacerun: yes;">       </span><span style="color: gray;">-</span>1<span style="mso-spacerun: yes;">      </span>2<span style="mso-spacerun: yes;">      </span></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; color: gray; font-family: &quot;Courier New&quot;; mso-no-proof: yes;">-</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;">1<span style="mso-spacerun: yes;">      </span>4<span style="mso-spacerun: yes;">       </span>4<span style="mso-spacerun: yes;">      </span></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; color: gray; font-family: &quot;Courier New&quot;; mso-no-proof: yes;">-</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;">1<span style="mso-spacerun: yes;">      </span>3<span style="mso-spacerun: yes;">       </span>3<span style="mso-spacerun: yes;">      </span></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt;"><span style="font-size: 10pt; color: gray; font-family: &quot;Courier New&quot;; mso-no-proof: yes;">-</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;">1<span style="mso-spacerun: yes;">      </span><span style="color: gray;">-</span>1<span style="mso-spacerun: yes;">      </span><span style="color: gray;">-</span>1<span style="mso-spacerun: yes;">  </span></span><span style="mso-bidi-font-size: 10.0pt;"><span style="mso-spacerun: yes;"><span style="font-size: small; font-family: Times New Roman;"> </span></span></span></p>
<p></code></p>
]]></content:encoded>
			<wfw:commentRss>http://rickcaminiti.com/tips/sql-server-computed-column/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>WTF is an Enum?</title>
		<link>http://rickcaminiti.com/code/wtf-enum/</link>
		<comments>http://rickcaminiti.com/code/wtf-enum/#comments</comments>
		<pubDate>Thu, 04 Jun 2009 14:01:19 +0000</pubDate>
		<dc:creator>NothingMan</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[g33k]]></category>
		<category><![CDATA[c#]]></category>
		<category><![CDATA[dotNet]]></category>
		<category><![CDATA[enum]]></category>
		<category><![CDATA[wtf]]></category>

		<guid isPermaLink="false">http://rickcaminiti.com/?p=348</guid>
		<description>I&amp;#8217;m a data-person but I like to change it up every now and then jump into some real code.  I was dabbling in C# last week and was looking into Enums.  I had heard about them a lot but never REALLY knew what they were or how they were constructed, so I forced myself to [...]</description>
			<content:encoded><![CDATA[<p>I&#8217;m a data-person but I like to change it up every now and then jump into some real code.  I was dabbling in C# last week and was looking into Enums.  I had heard about them a lot but never REALLY knew what they were or how they were constructed, so I forced myself to figure out WTF they were.</p>
<p> </p>
<p>In <a title="Computer programming" href="http://rickcaminiti.com/wiki/Computer_programming">computer programming</a>, an <strong>enumerated type</strong> (also called <strong>enumeration</strong> or <strong>enum</strong>) is a <a title="Data type" href="http://rickcaminiti.com/wiki/Data_type">data type</a> consisting of a set of named <a title="Value (computer science)" href="http://rickcaminiti.com/wiki/Value_(computer_science)">values</a> called <strong>elements</strong>, <strong>members</strong> or <strong>enumerators</strong> of the type. The enumerator names are usually <a title="Identifier" href="http://rickcaminiti.com/wiki/Identifier">identifiers</a> that behave as <a title="Constant (programming)" href="http://rickcaminiti.com/wiki/Constant_(programming)">constants</a> in the language. A <a class="mw-redirect" title="Variable (computer science)" href="http://rickcaminiti.com/wiki/Variable_(computer_science)">variable</a> that has been <a title="Declaration (computer science)" href="http://rickcaminiti.com/wiki/Declaration_(computer_science)">declared</a> as having an enumerated type can be assigned any of the enumerators as a value.</p>
<p>For example, the four suits in a deck of playing cards may be four enumerators named <em>CLUB</em>, <em>DIAMOND</em>, <em>HEART</em>, <em>SPADE</em>, belonging to an enumerated type named <em>suits</em>. If a variable <em>V</em> is declared having <em>suits</em> as its data type, one can assign any of those four values to it.</p>
<p>The enumerators are necessarily distinct, even though some languages may allow the same enumerator to be listed twice in the type&#8217;s declaration. The enumerators need not be complete or compatible in any sense. For example, an enumerated type called <em>color</em> may be defined to consist of the enumerators <em>RED</em>, <em>GREEN</em>, <em>ZEBRA</em>, and <em>MISSING</em>. In some languages, the declaration of an enumerated type also defines an <a title="Total order" href="http://rickcaminiti.com/wiki/Total_order">ordering</a> of its members.</p>
<p>Some enumerator types may be <a class="mw-redirect" title="Built-in type" href="http://rickcaminiti.com/wiki/Built-in_type">built into</a> the language. The <a class="mw-redirect" title="Boolean type" href="http://rickcaminiti.com/wiki/Boolean_type">Boolean type</a>, for example is often a pre-defined enumeration of the values <em>FALSE</em> and <em>TRUE</em>. Many languages allow the user to define new enumerated types.</p>
<p> </p>
<p>Here&#8217;s a quick look at how to create an Enum and how to use them.<br />
<code><br />
<span style="font-size: 10pt; color: blue; font-family: Verdana;">using</span><span style="font-size: 10pt; font-family: Verdana;"> System;</p>
<p><span style="color: green;">// declares the enum<br />
</span><span style="color: blue;">public</span> <span style="color: blue;">enum</span> Volume<br />
{<br />
   Low,<br />
   Medium,<br />
   High<br />
}<br />
<span style="color: green;"><br />
// demonstrates how to use the enum<br />
</span><span style="color: blue;"><br />
class</span> EnumSwitch<br />
{<br />
<span style="color: blue;">   static</span> <span style="color: blue;">void</span> Main()<br />
   {<br />
<span style="color: green;">      // create and initialize <br />
      // instance of enum type</span><br />
      Volume myVolume = Volume.Medium;<br />
<span style="color: green;"><br />
      // make decision based<br />
      // on enum value<br />
</span><span style="color: blue;">      switch</span> (myVolume)<br />
      {<br />
<span style="color: blue;">         case</span> Volume.Low:<br />
            Console.WriteLine("The volume has been turned Down.");<br />
<span style="color: blue;">            break</span>;<br />
<span style="color: blue;">         case</span> Volume.Medium:<br />
            Console.WriteLine("The volume is in the middle.");<br />
<span style="color: blue;">            break</span>;<br />
<span style="color: blue;">         case</span> Volume.High:<br />
            Console.WriteLine("The volume has been turned up.");<br />
<span style="color: blue;">            break</span>;<br />
      }<br />
      Console.ReadLine();<br />
   }<br />
}</span><span style="font-family: Verdana;"><span style="font-size: small;"> </span></span><br />
</code></p>
]]></content:encoded>
			<wfw:commentRss>http://rickcaminiti.com/code/wtf-enum/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Escape Syntax in T-SQL LIKE Statement with ‘_’</title>
		<link>http://rickcaminiti.com/tips/escape-syntax-tsql-statement/</link>
		<comments>http://rickcaminiti.com/tips/escape-syntax-tsql-statement/#comments</comments>
		<pubDate>Wed, 27 May 2009 21:33:05 +0000</pubDate>
		<dc:creator>NothingMan</dc:creator>
				<category><![CDATA[BI]]></category>
		<category><![CDATA[Code]]></category>
		<category><![CDATA[Tips]]></category>
		<category><![CDATA[sql]]></category>
		<category><![CDATA[tsql]]></category>
		<category><![CDATA[wildcard]]></category>

		<guid isPermaLink="false">http://rickcaminiti.com/?p=346</guid>
		<description>In a like statement, &amp;#8220;%&amp;#8221; is a wildcard for everything after or before it and &amp;#8220;_&amp;#8221; is a wildcard for one character.  Observe: LIKE &amp;#8216;%Z&amp;#8217; would return ANYthing that ended with Z.   LIKE &amp;#8216;%Z%&amp;#8217; would return ANYthing with a Z in it.   LIKE &amp;#8216;Z__&amp;#8217; would return anything that started with Z and had at least 2 [...]</description>
			<content:encoded><![CDATA[<p>In a like statement, &#8220;%&#8221; is a wildcard for everything after or before it and &#8220;_&#8221; is a wildcard for one character.  Observe:</p>
<p class="MsoNormal" style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"><span style="FONT-SIZE: 10pt; COLOR: gray; FONT-FAMILY: 'Courier New'; mso-no-proof: yes">LIKE</span><span style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"> <span style="COLOR: red">&#8216;%Z&#8217;</span></span> would return ANYthing that ended with Z.</p>
<p class="MsoNormal" style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"> </p>
<p class="MsoNormal" style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"><span style="FONT-SIZE: 10pt; COLOR: gray; FONT-FAMILY: 'Courier New'; mso-no-proof: yes">LIKE</span><span style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"> <span style="COLOR: red">&#8216;%Z%&#8217;</span></span> would return ANYthing with a Z in it.</p>
<p class="MsoNormal" style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"> </p>
<p class="MsoNormal" style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"><span style="FONT-SIZE: 10pt; COLOR: gray; FONT-FAMILY: 'Courier New'; mso-no-proof: yes">LIKE</span><span style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"> <span style="COLOR: red">&#8216;Z__&#8217;</span></span> would return anything that started with Z and had at least 2 characters after it, like:</p>
<p class="MsoNormal" style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none">ZOO, ZXY, ZAP</p>
<p class="MsoNormal" style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none">but would not return:</p>
<p class="MsoNormal" style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none">ZA, ZO, Z, or XYZ</p>
<p class="MsoNormal" style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"> </p>
<p class="MsoNormal" style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"><span style="FONT-SIZE: 10pt; COLOR: gray; FONT-FAMILY: 'Courier New'; mso-no-proof: yes">LIKE</span><span style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"> <span style="COLOR: red">&#8216;Z%&#8217;</span></span> would return anything that STARTED with Z.</p>
<p class="MsoNormal" style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"> </p>
<p class="MsoNormal" style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none"><span style="FONT-SIZE: 10pt; COLOR: gray; FONT-FAMILY: 'Courier New'; mso-no-proof: yes">LIKE</span><span style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"> <span style="COLOR: red">&#8216;_Z%&#8217;</span></span> would return anything that had one character, then a Z, then anything or nothing else like:</p>
<p class="MsoNormal" style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none">YZX, YZ, ZZZ</p>
<p class="MsoNormal" style="MARGIN: 0in 0in 0pt">but would not return:</p>
<p class="MsoNormal" style="MARGIN: 0in 0in 0pt">XYZ, ABCZ</p>
<p class="MsoNormal" style="MARGIN: 0in 0in 0pt"> </p>
<p>However, if you want to look for the literal value of <span style="font-size: x-small; color: #ff0000;">&#8216;%&#8217;</span> or <span style="font-size: x-small; color: #ff0000;">&#8216;_&#8217;</span>, you need to escape it.  For instance, if you want to look for anything that begins with <span style="font-size: x-small; color: #ff0000;"><span style="font-size: x-small; color: #ff0000;">&#8216;Z_&#8217;</span></span>, then you would need to escape the <span style="font-size: x-small; color: #ff0000;">&#8216;_&#8217;</span>, otherwise, you would be looking for anything that started with <span style="font-size: x-small; color: #ff0000;">&#8216;Z&#8217; </span>followed by one wildcard character <span style="font-size: x-small; color: #ff0000;">&#8216;_&#8217;</span>, followed by a wildcard of any number of characters <span style="font-size: x-small; color: #ff0000;">&#8216;%&#8217;</span>, returning anything that just started with <span style="font-size: x-small; color: #ff0000;">&#8216;Z&#8217;</span> and had at lease one character after it.</p>
<p><code><span style="font-size: 10pt; color: blue; font-family: &quot;Courier New&quot;; mso-no-proof: yes;">select</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"> table_catalog<span style="color: gray;">,</span> column_name<span style="color: gray;">,</span> table_schema<span style="color: gray;">,</span> table_name<br />
</span><span style="font-size: 10pt; color: blue; font-family: &quot;Courier New&quot;; mso-no-proof: yes;">from</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"> information_schema<span style="color: gray;">.</span>columns<br />
</span><span style="font-size: 10pt; color: blue; font-family: &quot;Courier New&quot;; mso-no-proof: yes;">where</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"> column_name <span style="color: gray;">like</span> <span style="color: red;">'Z\_%'</span> <span style="color: blue;">escape</span> <span style="color: red;">'\'</span></span></code></p>
<p><code><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="color: red;"><span style="color: #000000;">This would only return data that started with <span style="color: red;">'Z_'</span>.</span></span></span></code></p>
]]></content:encoded>
			<wfw:commentRss>http://rickcaminiti.com/tips/escape-syntax-tsql-statement/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Generate ROWNUM pseudo-column in SSIS</title>
		<link>http://rickcaminiti.com/tips/generate-rownum-pseudocolumn-ssis/</link>
		<comments>http://rickcaminiti.com/tips/generate-rownum-pseudocolumn-ssis/#comments</comments>
		<pubDate>Wed, 27 May 2009 15:43:32 +0000</pubDate>
		<dc:creator>NothingMan</dc:creator>
				<category><![CDATA[BI]]></category>
		<category><![CDATA[Code]]></category>
		<category><![CDATA[Tips]]></category>
		<category><![CDATA[equivalents]]></category>
		<category><![CDATA[ssis]]></category>
		<category><![CDATA[vb.net]]></category>

		<guid isPermaLink="false">http://rickcaminiti.com/?p=344</guid>
		<description>I posted earlier on how to generate a rownumber in SQL 2000, but that would not work as a source query in SSIS for some reason.  Without having to create a stored procedure or temp tables based on other temp tables, I wanted a simple way to generate this rownum in SSIS.  I was considering [...]</description>
			<content:encoded><![CDATA[<p>I posted earlier on how to generate a <a title="rownum equivalent in sql 2000 and 2005" href="http://rickcaminiti.com/tips/rownum-equivalent-sql-2000/" target="_self">rownumber in SQL 2000</a>, but that would not work as a source query in SSIS for some reason.  Without having to create a stored procedure or temp tables based on other temp tables, I wanted a simple way to generate this rownum in SSIS.  I was considering something with variable expressions, but then I found a way to do it with a <a title="Creating a row counter in SSIS" href="http://support.microsoft.com/kb/908460" target="_blank">Script Component</a>.</p>
<p>Drag a Script Component Task into your DataFlow and connect it between your source and destination tasks.  Open it up and click &#8220;Inputs and Outputs&#8221;.  Double Click &#8220;Output 0&#8243; and highlight &#8220;Output Columns&#8221; and click Add Column.  For this code to work, name that new column &#8220;<strong>rownum</strong>&#8220;.</p>
<p>Then open the script tab and click &#8220;Design Script&#8221; and paste this code over what is already there:</p>
<p> <code> </code></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; color: blue; font-family: &quot;Courier New&quot;; mso-no-proof: yes;">Imports</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="color: #000000;"> System</span></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; color: blue; font-family: &quot;Courier New&quot;; mso-no-proof: yes;">Imports</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="color: #000000;"> System.Data</span></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; color: blue; font-family: &quot;Courier New&quot;; mso-no-proof: yes;">Imports</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="color: #000000;"> System.Math</span></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; color: blue; font-family: &quot;Courier New&quot;; mso-no-proof: yes;">Imports</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="color: #000000;"> Microsoft.SqlServer.Dts.Pipeline.Wrapper</span></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; color: blue; font-family: &quot;Courier New&quot;; mso-no-proof: yes;">Imports</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="color: #000000;"> Microsoft.SqlServer.Dts.Runtime.Wrapper</span></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="color: #000000;"> </span></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; color: blue; font-family: &quot;Courier New&quot;; mso-no-proof: yes;">Public</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="color: #000000;"> </span><span style="color: blue;">Class</span><span style="color: #000000;"> ScriptMain</span></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;"><span style="color: #000000;">    </span></span><span style="color: blue;">Inherits</span><span style="color: #000000;"> UserComponent</span></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;"><span style="color: #000000;">    </span></span><span style="color: blue;">Dim</span><span style="color: #000000;"> counter </span><span style="color: blue;">As</span><span style="color: #000000;"> </span><span style="color: blue;">Integer</span><span style="color: #000000;"> = 0</span></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="color: #000000;"> </span></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;"><span style="color: #000000;">    </span></span><span style="color: blue;">Public</span><span style="color: #000000;"> </span><span style="color: blue;">Overrides</span><span style="color: #000000;"> </span><span style="color: blue;">Sub</span><span style="color: #000000;"> Input0_ProcessInputRow(</span><span style="color: blue;">ByVal</span><span style="color: #000000;"> Row </span><span style="color: blue;">As</span><span style="color: #000000;"> Input0Buffer)</span></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"> </p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="color: #000000;"><span style="mso-spacerun: yes;">        </span>Row.rownum= counter</span></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="color: #000000;"><span style="mso-spacerun: yes;">        </span>counter = counter + 1</span></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;"><span style="color: #000000;">    </span></span><span style="color: blue;">End</span><span style="color: #000000;"> </span><span style="color: blue;">Sub</span></span><span style="font-size: 10pt; color: blue; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"> </span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt;"><span style="font-size: 10pt; color: blue; font-family: &quot;Courier New&quot;; mso-no-proof: yes;">End</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="color: #000000;"> </span><span style="color: blue;">Class</span></span></p>
<p><span style="font-size: x-small; color: #0000ff;"><span style="font-size: x-small; color: #0000ff;"> </span></span></p>
]]></content:encoded>
			<wfw:commentRss>http://rickcaminiti.com/tips/generate-rownum-pseudocolumn-ssis/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>T-SQL Delete Join</title>
		<link>http://rickcaminiti.com/tips/tsql-delete-join/</link>
		<comments>http://rickcaminiti.com/tips/tsql-delete-join/#comments</comments>
		<pubDate>Fri, 22 May 2009 14:56:15 +0000</pubDate>
		<dc:creator>NothingMan</dc:creator>
				<category><![CDATA[BI]]></category>
		<category><![CDATA[Code]]></category>
		<category><![CDATA[Tips]]></category>
		<category><![CDATA[etl]]></category>
		<category><![CDATA[mssql]]></category>
		<category><![CDATA[sql]]></category>

		<guid isPermaLink="false">http://rickcaminiti.com/?p=342</guid>
		<description>Here&amp;#8217;s are two quick ways to Delete data in one table based on another table.  This works perfectly in an ETL job where you have a staging table that indicate whether to Insert, Update, or Delete the data in the other table. The first one uses an inner join, the second uses a simple EXISTS [...]</description>
			<content:encoded><![CDATA[<p>Here&#8217;s are two quick ways to Delete data in one table based on another table.  This works perfectly in an ETL job where you have a staging table that indicate whether to Insert, Update, or Delete the data in the other table.</p>
<p>The first one uses an inner join, the second uses a simple EXISTS clause.</p>
<p><code></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; color: blue; font-family: &quot;Courier New&quot;; mso-no-proof: yes;">DELETE</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"> b</span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;">  </span><span style="color: blue;">FROM</span> [dbo]<span style="color: gray;">.</span>[TABLE_1] b</span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span><span style="color: gray;">INNER</span> <span style="color: gray;">JOIN</span> [dbo]<span style="color: gray;">.</span>[TABLE_2] w</span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;">    </span><span style="color: blue;">ON</span> b<span style="color: gray;">.</span>[ROW_ID] <span style="color: gray;">=</span> w<span style="color: gray;">.</span>[ROW_ID]</span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span><span style="color: blue;">WHERE</span> w<span style="color: gray;">.</span>[CTRL_CD] <span style="color: gray;">=</span> <span style="color: red;">'D'</span></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; color: red; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"> </span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; color: red; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"> </span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; color: blue; font-family: &quot;Courier New&quot;; mso-no-proof: yes;">DELETE</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"> b</span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;">  </span><span style="color: blue;">FROM</span> [dbo]<span style="color: gray;">.</span>[TABLE_1] b</span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span><span style="color: blue;">WHERE</span> <span style="color: gray;">EXISTS</span> <span style="color: gray;">(</span></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-tab-count: 2;">            </span><span style="color: blue;">SELECT</span> 1</span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;">          </span><span style="color: blue;">FROM</span> [dbo]<span style="color: gray;">.</span>[TABLE_2] w</span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;">         </span><span style="color: blue;">WHERE</span> b<span style="color: gray;">.</span>[ROW_ID] <span style="color: gray;">=</span> w<span style="color: gray;">.</span>[ROW_ID]</span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;">           </span><span style="color: gray;">AND</span> w<span style="color: gray;">.</span>[CTRL_CD] <span style="color: gray;">=</span> <span style="color: red;">'D'</span><span style="color: gray;">)</span></span></p>
<p> </p>
<p></code></p>
]]></content:encoded>
			<wfw:commentRss>http://rickcaminiti.com/tips/tsql-delete-join/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Google Geocoding in SSIS</title>
		<link>http://rickcaminiti.com/misc/google-geocoding-ssis/</link>
		<comments>http://rickcaminiti.com/misc/google-geocoding-ssis/#comments</comments>
		<pubDate>Wed, 20 May 2009 17:46:18 +0000</pubDate>
		<dc:creator>NothingMan</dc:creator>
				<category><![CDATA[BI]]></category>
		<category><![CDATA[Code]]></category>
		<category><![CDATA[Misc]]></category>
		<category><![CDATA[g33k]]></category>
		<category><![CDATA[geocode]]></category>
		<category><![CDATA[google]]></category>
		<category><![CDATA[ssis]]></category>

		<guid isPermaLink="false">http://rickcaminiti.com/?p=337</guid>
		<description>I have an old YouTube tutorial on how to use Google Geocoding within SSIS, but I lost all the downloadable scripts.  I recently had a few people asking me if I could send them the scripts, so I deiceded to rewrite them. Again, you can check out the YouTub video (it&amp;#8217;s rough) for more details, just [...]</description>
			<content:encoded><![CDATA[<p>I have an old YouTube tutorial on how to use Google Geocoding within SSIS, but I lost all the downloadable scripts.  I recently had a few people asking me if I could send them the scripts, so I deiceded to rewrite them.</p>
<p>Again, you can check out the YouTub video (it&#8217;s rough) for more details, just go to <a href="http://www.youtube.com/watch?v=HTSHzR-wSgc">http://www.youtube.com/watch?v=HTSHzR-wSgc</a> with this DISCLAIMER:  This code was just thrown together and is quite ugly and my microphone was terrible, I usually sound much better than that <img src='http://rickcaminiti.com/wp-includes/images/smilies/icon_smile.gif' alt="Google Geocoding in SSIS" class='wp-smiley' title="Google Geocoding in SSIS photo" />  :-)</p>
<p>In a nutshell, I sniped about 18,000 golfcourses off the web with a PHP script and got basic course information for all of them, including the address information.  I wanted to use Google Maps to display these courses, so I thought I&#8217;d use Google Geocoding.  Caution, they don&#8217;t like it when you hit them 1000 times per second, so I would recommend using a <a title="Putting VB.Net 2008 to Sleep" href="http://rickcaminiti.com/tips/putting-vbnet-2008-to-sleep/" target="_self">Sleep command </a>in your code like I did so you can throttle it without getting kicked off. </p>
<p>So, I have an OLE Source task that reads from my database.  I created a Derived Column task to create placeholders for latitude, longitude, and level of accuracy.  I created a Script Component and selected street, city, state, and zip as input columns and added lat, long, and accuracy as read/write columns. </p>
<p>Open the script editor, add a reference to System.Web, then create a new class called Google GeoCode, or whatever the heck you want to call it and paste in this code:</p>
<div><code><span style="font-size: 10pt; color: blue; font-family: &quot;Courier New&quot;; mso-no-proof: yes;">Option</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"> <span style="color: blue;">Strict</span> <span style="color: blue;">Off</span></span></code></div>
<p><code></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; color: green; font-family: &quot;Courier New&quot;; mso-no-proof: yes;">''' Might need this, might not</span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; color: blue; font-family: &quot;Courier New&quot;; mso-no-proof: yes;">Imports</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"> System</span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; color: blue; font-family: &quot;Courier New&quot;; mso-no-proof: yes;">Imports</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"> System.Data</span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; color: blue; font-family: &quot;Courier New&quot;; mso-no-proof: yes;">Imports</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"> System.Math</span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; color: blue; font-family: &quot;Courier New&quot;; mso-no-proof: yes;">Imports</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"> System.Net</span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; color: blue; font-family: &quot;Courier New&quot;; mso-no-proof: yes;">Imports</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"> System.Web</span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; color: blue; font-family: &quot;Courier New&quot;; mso-no-proof: yes;">Imports</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"> System.IO</span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; color: blue; font-family: &quot;Courier New&quot;; mso-no-proof: yes;">Namespace</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"> GoogleGeoCoder</span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;">    </span><span style="color: blue;">Public</span> <span style="color: blue;">Interface</span> ISpatialCoordinate</span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;">        </span><span style="color: blue;">Property</span> latitude() <span style="color: blue;">As</span> <span style="color: blue;">Double</span></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;">        </span><span style="color: blue;">Property</span> longitude() <span style="color: blue;">As</span> <span style="color: blue;">Double</span></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span><span style="mso-spacerun: yes;">   </span><span style="color: blue;">End</span> <span style="color: blue;">Interface</span></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;">    </span><span style="color: green;">''' &lt;summary&gt;<span style="mso-spacerun: yes;">    </span></span></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;">    </span><span style="color: green;">''' Coordiate structure. Holds Latitude and Longitude.<span style="mso-spacerun: yes;">    </span></span></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;">    </span><span style="color: green;">''' &lt;/summary&gt;<span style="mso-spacerun: yes;">    </span></span></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;">    </span><span style="color: blue;">Public</span> <span style="color: blue;">Structure</span> Coordinate</span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;">        </span><span style="color: blue;">Implements</span> ISpatialCoordinate</span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"> </span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;">        </span><span style="color: blue;">Private</span> _latitude <span style="color: blue;">As</span> <span style="color: blue;">Double</span></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;">        </span><span style="color: blue;">Private</span> _longitude <span style="color: blue;">As</span> <span style="color: blue;">Double</span></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; color: blue; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"> </span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;">        </span><span style="color: blue;">Public</span> <span style="color: blue;">Sub</span> <span style="color: blue;">New</span>(<span style="color: blue;">ByVal</span> lattitude <span style="color: blue;">As</span> <span style="color: blue;">Double</span>, <span style="color: blue;">ByVal</span> longitude <span style="color: blue;">As</span> <span style="color: blue;">Double</span>)</span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;">            </span>_latitude = lattitude</span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;">            </span>_longitude = longitude</span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;">        </span><span style="color: blue;">End</span> <span style="color: blue;">Sub</span></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; color: blue; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"> </span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;">        </span><span style="color: blue;">Public</span> <span style="color: blue;">Property</span> latitude() <span style="color: blue;">As</span> <span style="color: blue;">Double</span> <span style="color: blue;">Implements</span> ISpatialCoordinate.latitude</span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;">            </span><span style="color: blue;">Get</span></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;">                </span><span style="color: blue;">Return</span> _latitude</span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;">            </span><span style="color: blue;">End</span> <span style="color: blue;">Get</span></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;">            </span><span style="color: blue;">Set</span>(<span style="color: blue;">ByVal</span> value <span style="color: blue;">As</span> <span style="color: blue;">Double</span>)</span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;">                </span>_latitude = value</span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;">            </span><span style="color: blue;">End</span> <span style="color: blue;">Set</span></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;">        </span><span style="color: blue;">End</span> <span style="color: blue;">Property</span></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; color: blue; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"> </span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;">        </span><span style="color: blue;">Public</span> <span style="color: blue;">Property</span> longitude() <span style="color: blue;">As</span> <span style="color: blue;">Double</span> <span style="color: blue;">Implements</span> ISpatialCoordinate.longitude</span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;">            </span><span style="color: blue;">Get</span></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;">                </span><span style="color: blue;">Return</span> _longitude</span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;">            </span><span style="color: blue;">End</span> <span style="color: blue;">Get</span></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;">            </span><span style="color: blue;">Set</span>(<span style="color: blue;">ByVal</span> value <span style="color: blue;">As</span> <span style="color: blue;">Double</span>)</span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;">                </span>_longitude = value</span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;">            </span><span style="color: blue;">End</span> <span style="color: blue;">Set</span></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;">        </span><span style="color: blue;">End</span> <span style="color: blue;">Property</span></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; color: blue; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"> </span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;">    </span><span style="color: blue;">End</span> <span style="color: blue;">Structure</span></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;">    </span><span style="color: blue;">Public</span> <span style="color: blue;">Class</span> GeoCode</span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;">        </span><span style="color: blue;">Const</span> _googleUri <span style="color: blue;">As</span> <span style="color: blue;">String</span> = <span style="color: maroon;">"http://maps.google.com/maps/geo?q="</span></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;">        </span><span style="color: blue;">Const</span> _googleKey <span style="color: blue;">As</span> <span style="color: blue;">String</span> = <span style="color: maroon;">"yourgooglekeyhere"</span><span style="mso-spacerun: yes;">  </span><span style="color: green;">' get your own<span style="mso-spacerun: yes;">        </span></span></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;">        </span><span style="color: blue;">Const</span> _outputType <span style="color: blue;">As</span> <span style="color: blue;">String</span> = <span style="color: maroon;">"csv"</span></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;">        </span><span style="color: blue;">Private</span> <span style="color: blue;">Shared</span> <span style="color: blue;">Function</span> GetGeoCodeUri(<span style="color: blue;">ByVal</span> address <span style="color: blue;">As</span> <span style="color: blue;">String</span>) <span style="color: blue;">As</span> Uri</span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;">            </span>address = HttpUtility.UrlEncode(address)</span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;">            </span><span style="color: blue;">Return</span> <span style="color: blue;">New</span> Uri(<span style="color: blue;">String</span>.Format(<span style="color: maroon;">"{0}{1}&amp;output={2}&amp;key={3}"</span>, _googleUri, address, _outputType, _googleKey))</span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;">        </span><span style="color: blue;">End</span> <span style="color: blue;">Function</span></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;">        </span><span style="color: green;">''' &lt;summary&gt;<span style="mso-spacerun: yes;">        </span></span></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;">        </span><span style="color: green;">''' Gets a Coordinate from a address.<span style="mso-spacerun: yes;">        </span></span></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;">        </span><span style="color: green;">''' &lt;/summary&gt;<span style="mso-spacerun: yes;">        </span></span></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;">        </span><span style="color: green;">''' &lt;param name="address"&gt;An address.<span style="mso-spacerun: yes;">        </span></span></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;">        </span><span style="color: green;">''' &lt;remarks&gt;<span style="mso-spacerun: yes;">        </span></span></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;">        </span><span style="color: green;">''' &lt;example&gt;1600 Amphitheatre Parkway Mountain View, CA 94043&lt;/example&gt;<span style="mso-spacerun: yes;">        </span></span></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;">        </span><span style="color: green;">''' &lt;/remarks&gt;<span style="mso-spacerun: yes;">        </span></span></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;">        </span><span style="color: green;">''' &lt;/param&gt;<span style="mso-spacerun: yes;">        </span></span></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;">        </span><span style="color: green;">''' &lt;returns&gt;A spatial coordinate that contains the latitude and longitude of the address.&lt;/returns&gt;<span style="mso-spacerun: yes;">        </span></span></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;">        </span><span style="color: blue;">Public</span> <span style="color: blue;">Shared</span> <span style="color: blue;">Function</span> GetCoordinates(<span style="color: blue;">ByVal</span> address <span style="color: blue;">As</span> <span style="color: blue;">String</span>) <span style="color: blue;">As</span> Coordinate</span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;">            </span><span style="color: blue;">Dim</span> client <span style="color: blue;">As</span> WebClient = <span style="color: blue;">New</span> WebClient()</span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;">            </span><span style="color: blue;">Dim</span> uri <span style="color: blue;">As</span> Uri = GetGeoCodeUri(address)</span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;">            </span><span style="color: blue;">Dim</span> geoCodeInfo <span style="color: blue;">As</span> <span style="color: blue;">String</span>()</span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;">            </span><span style="color: green;">'The first number is the status code,<span style="mso-spacerun: yes;">             </span></span></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;">            </span><span style="color: green;">'the second is the accuracy,<span style="mso-spacerun: yes;">             </span></span></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;">       </span><span style="mso-spacerun: yes;">     </span><span style="color: green;">'the third is the latitude,<span style="mso-spacerun: yes;">             </span></span></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;">            </span><span style="color: green;">'the fourth one is the longitude.<span style="mso-spacerun: yes;">            </span></span></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;">            </span><span style="color: blue;">Try</span></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;">                </span>geoCodeInfo = client.DownloadString(uri).Split(<span style="color: maroon;">","</span>)</span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;">                </span><span style="color: blue;">Return</span> <span style="color: blue;">New</span> Coordinate(Convert.ToDouble(geoCodeInfo(2)), Convert.ToDouble(geoCodeInfo(3)))</span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;">            </span><span style="color: blue;">Catch</span> ex <span style="color: blue;">As</span> Exception</span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;">                </span><span style="color: blue;">Return</span> <span style="color: blue;">New</span> Coordinate(0.0, 0.0)</span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;">            </span><span style="color: blue;">End</span> <span style="color: blue;">Try</span></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;">        </span><span style="color: blue;">End</span> <span style="color: blue;">Function</span></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;">    </span><span style="color: blue;">End</span> <span style="color: blue;">Class</span></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; color: blue; font-family: &quot;Courier New&quot;; mso-no-proof: yes;">End</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"> <span style="color: blue;">Namespace</span></span></p>
<p></code></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"> </p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;">Save it and then go back to the main script and add Import that class (see code).  Notice, the way I&#8217;m getting the level of accuracy with my ugly nested IF statements isn&#8217;t the prettiest way to do this, use your imagination.  Copy in this code into the Main Script:</p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"> </p>
<p><code></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; color: green; font-family: &quot;Courier New&quot;; mso-no-proof: yes;">' Microsoft SQL Server Integration Services user script component</span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; color: green; font-family: &quot;Courier New&quot;; mso-no-proof: yes;">' This is your new script component in Microsoft Visual Basic .NET</span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; color: green; font-family: &quot;Courier New&quot;; mso-no-proof: yes;">' ScriptMain is the entrypoint class for script components</span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; color: green; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"> </span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; color: blue; font-family: &quot;Courier New&quot;; mso-no-proof: yes;">Imports</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"> System</span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; color: blue; font-family: &quot;Courier New&quot;; mso-no-proof: yes;">Imports</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"> System.Data</span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; color: blue; font-family: &quot;Courier New&quot;; mso-no-proof: yes;">Imports</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"> System.Math</span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; color: blue; font-family: &quot;Courier New&quot;; mso-no-proof: yes;">Imports</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"> Microsoft.SqlServer.Dts.Pipeline.Wrapper</span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; color: blue; font-family: &quot;Courier New&quot;; mso-no-proof: yes;">Imports</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"> Microsoft.SqlServer.Dts.Runtime.Wrapper</span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; color: blue; font-family: &quot;Courier New&quot;; mso-no-proof: yes;">Imports</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"> ScriptComponent_4a8732cababc49a999159a91c737082a.GoogleGeoCoder</span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"> </span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; color: blue; font-family: &quot;Courier New&quot;; mso-no-proof: yes;">Public</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"> <span style="color: blue;">Class</span> ScriptMain</span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;">    </span><span style="color: blue;">Inherits</span> UserComponent</span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"> </span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;">    </span><span style="color: blue;">Public</span> <span style="color: blue;">Overrides</span> <span style="color: blue;">Sub</span> Input0_ProcessInputRow(<span style="color: blue;">ByVal</span> Row <span style="color: blue;">As</span> Input0Buffer)</span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"> </span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;">        </span><span style="color: blue;">Dim</span> coordinate <span style="color: blue;">As</span> Coordinate = GeoCode.GetCoordinates(Row.street &amp; <span style="color: maroon;">", "</span> &amp; Row.city &amp; <span style="color: maroon;">", "</span> &amp; Row.state &amp; <span style="color: maroon;">", "</span> &amp; Row.zip)</span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"> </span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;">        </span><span style="color: blue;">If</span> ((coordinate.latitude &lt;&gt; 0) <span style="color: blue;">And</span> (coordinate.longitude &lt;&gt; 0)) <span style="color: blue;">Then</span></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;">            </span>Row.lat = Convert.ToDecimal(coordinate.latitude)</span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;">            </span>Row.long = Convert.ToDecimal(coordinate.longitude)</span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;">            </span>Row.acc = 1</span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;">        </span><span style="color: blue;">Else</span></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;">            </span>coordinate = GeoCode.GetCoordinates(Row.city &amp; <span style="color: maroon;">", "</span> &amp; Row.state &amp; <span style="color: maroon;">", "</span> &amp; Row.zip)</span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;">            </span><span style="color: blue;">If</span> ((coordinate.latitude &lt;&gt; 0) <span style="color: blue;">And</span> (coordinate.longitude &lt;&gt; 0)) <span style="color: blue;">Then</span></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;">                </span>Row.lat = Convert.ToDecimal(coordinate.latitude)</span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;">                </span>Row.long = Convert.ToDecimal(coordinate.longitude)</span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;">                </span>Row.acc = 2</span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;">            </span><span style="color: blue;">Else</span></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;">                </span>coordinate = GeoCode.GetCoordinates(Row.zip)</span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;">                </span><span style="color: blue;">If</span> ((coordinate.latitude &lt;&gt; 0) <span style="color: blue;">And</span> (coordinate.longitude &lt;&gt; 0)) <span style="color: blue;">Then</span></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;">                    </span>Row.lat = Convert.ToDecimal(coordinate.latitude)</span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;">                    </span>Row.long = Convert.ToDecimal(coordinate.longitude)</span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;">                    </span>Row.acc = 3</span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;">                </span><span style="color: blue;">Else</span></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;">                    </span>coordinate = GeoCode.GetCoordinates(Row.city &amp; <span style="color: maroon;">", "</span> &amp; Row.state)</span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;">                    </span><span style="color: blue;">If</span> ((coordinate.latitude &lt;&gt; 0) <span style="color: blue;">And</span> (coordinate.longitude &lt;&gt; 0)) <span style="color: blue;">Then</span></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;">                        </span>Row.lat = Convert.ToDecimal(coordinate.latitude)</span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;">                        </span>Row.long = Convert.ToDecimal(coordinate.longitude)</span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;">                        </span>Row.acc = 4</span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;">                    </span><span style="color: blue;">Else</span></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;">                        </span>coordinate = GeoCode.GetCoordinates(Row.state)</span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;">                        </span><span style="color: blue;">If</span> ((coordinate.latitude &lt;&gt; 0) <span style="color: blue;">And</span> (coordinate.longitude &lt;&gt; 0)) <span style="color: blue;">Then</span></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;">                            </span>Row.lat = Convert.ToDecimal(coordinate.latitude)</span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;">                            </span>Row.long = Convert.ToDecimal(coordinate.longitude)</span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;">                            </span>Row.acc = 5</span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;">                        </span><span style="color: blue;">End</span> <span style="color: blue;">If</span></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;">                    </span><span style="color: blue;">End</span> <span style="color: blue;">If</span></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;">                </span><span style="color: blue;">End</span> <span style="color: blue;">If</span></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;">            </span><span style="color: blue;">End</span> <span style="color: blue;">If</span></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;">        </span><span style="color: blue;">End</span> <span style="color: blue;">If</span></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;">    </span><span style="color: blue;">End</span> <span style="color: blue;">Sub</span></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; color: blue; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"> </span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; color: blue; font-family: &quot;Courier New&quot;; mso-no-proof: yes;">End</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"> <span style="color: blue;">Class</span></span></p>
<p> </p>
<p></code></p>
]]></content:encoded>
			<wfw:commentRss>http://rickcaminiti.com/misc/google-geocoding-ssis/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>RowNum() Equivalent in SQL 2000+</title>
		<link>http://rickcaminiti.com/tips/rownum-equivalent-sql-2000/</link>
		<comments>http://rickcaminiti.com/tips/rownum-equivalent-sql-2000/#comments</comments>
		<pubDate>Mon, 18 May 2009 15:02:06 +0000</pubDate>
		<dc:creator>NothingMan</dc:creator>
				<category><![CDATA[BI]]></category>
		<category><![CDATA[Code]]></category>
		<category><![CDATA[Tips]]></category>
		<category><![CDATA[equivalent]]></category>
		<category><![CDATA[mssql]]></category>
		<category><![CDATA[oracle]]></category>
		<category><![CDATA[sql]]></category>

		<guid isPermaLink="false">http://rickcaminiti.com/?p=330</guid>
		<description>Oracle has a pseudo-column called ROWNUM that allows you to display the row number for each row.  There are infinite reasons why you might want to use the ROWNUM, but in SQL it&amp;#8217;s not nearly as easy to determine.   In Oracle, it&amp;#8217;s simply SELECT ROWNUM from table_name   In SQL 2005+, there is actually [...]</description>
			<content:encoded><![CDATA[<p class="MsoNormal" style="margin: 0in 0in 0pt;"><span style="font-size: small; font-family: Times New Roman;">Oracle has a pseudo-column called ROWNUM that allows you to display the row number for each row.  There are infinite reasons why you might want to use the ROWNUM, but in SQL it&#8217;s not nearly as easy to determine.</span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt;"><span style="font-size: small; font-family: Times New Roman;"> </span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt;"><span style="font-size: small; font-family: Times New Roman;">In Oracle, it&#8217;s simply</span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt;"><span style="font-size: small; font-family: Times New Roman;"><code></span><span style="font-size: 10pt; color: blue; font-family: &quot;Courier New&quot;; mso-bidi-font-size: 12.0pt;">SELECT</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-bidi-font-size: 12.0pt;"> ROWNUM <span style="color: blue;">from</span> table_name</span><span style="font-size: small;"><span style="font-family: Times New Roman;"></code><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-bidi-font-size: 12.0pt;"></span></span></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt;"><span style="font-size: small; font-family: Times New Roman;"> </span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt;"><span style="font-size: small; font-family: Times New Roman;">In SQL 2005+, there is actually a ROW_NUMBER() function, but you have to give it some more information to use it.</span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; line-height: 13.5pt; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt;"><span style="font-size: small; font-family: Times New Roman;"><code></span><span style="font-size: 9pt; color: black; font-family: &quot;Courier New&quot;;">ROW_NUMBER <strong>(</strong> <strong>)</strong>     OVER <strong>(</strong> [ &lt;partition_by_clause&gt; ] &lt;order_by_clause&gt; <strong>)</strong></span><span style="font-size: small;"><span style="font-family: Times New Roman;"> </code><span style="font-size: 9pt; color: black; font-family: &quot;Courier New&quot;;"></span></span></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt;"><span style="font-size: 10pt; color: black; font-family: Verdana;"> </span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt;"><span style="font-size: 10pt; color: black; font-family: Verdana;">For example:</span><span style="font-size: 10pt; color: black; font-family: &quot;Courier New&quot;;"><br />
</span><span style="font-size: small; font-family: Times New Roman;"><code></span><span style="font-size: 10pt; color: blue; font-family: &quot;Courier New&quot;; mso-no-proof: yes; mso-bidi-font-size: 12.0pt;">use</span><span style="font-size: 10pt; color: black; font-family: &quot;Courier New&quot;; mso-no-proof: yes; mso-bidi-font-size: 12.0pt;"> [Database]</span><span style="font-size: 10pt; color: black; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><br />
</span><span style="font-size: 10pt; color: blue; font-family: &quot;Courier New&quot;; mso-no-proof: yes; mso-bidi-font-size: 12.0pt;">select</span><span style="font-size: 10pt; color: black; font-family: &quot;Courier New&quot;; mso-no-proof: yes; mso-bidi-font-size: 12.0pt;"> </span><span style="font-size: 10pt; color: fuchsia; font-family: &quot;Courier New&quot;; mso-no-proof: yes; mso-bidi-font-size: 12.0pt;">row_number</span><span style="font-size: 10pt; color: gray; font-family: &quot;Courier New&quot;; mso-no-proof: yes; mso-bidi-font-size: 12.0pt;">()</span><span style="font-size: 10pt; color: black; font-family: &quot;Courier New&quot;; mso-no-proof: yes; mso-bidi-font-size: 12.0pt;"> </span><span style="font-size: 10pt; color: blue; font-family: &quot;Courier New&quot;; mso-no-proof: yes; mso-bidi-font-size: 12.0pt;">over</span><span style="font-size: 10pt; color: black; font-family: &quot;Courier New&quot;; mso-no-proof: yes; mso-bidi-font-size: 12.0pt;"> </span><span style="font-size: 10pt; color: gray; font-family: &quot;Courier New&quot;; mso-no-proof: yes; mso-bidi-font-size: 12.0pt;">(</span><span style="font-size: 10pt; color: blue; font-family: &quot;Courier New&quot;; mso-no-proof: yes; mso-bidi-font-size: 12.0pt;">order</span><span style="font-size: 10pt; color: black; font-family: &quot;Courier New&quot;; mso-no-proof: yes; mso-bidi-font-size: 12.0pt;"> </span><span style="font-size: 10pt; color: blue; font-family: &quot;Courier New&quot;; mso-no-proof: yes; mso-bidi-font-size: 12.0pt;">by</span><span style="font-size: 10pt; color: black; font-family: &quot;Courier New&quot;; mso-no-proof: yes; mso-bidi-font-size: 12.0pt;"> data_srce_id </span><span style="font-size: 10pt; color: blue; font-family: &quot;Courier New&quot;; mso-no-proof: yes; mso-bidi-font-size: 12.0pt;">desc</span><span style="font-size: 10pt; color: gray; font-family: &quot;Courier New&quot;; mso-no-proof: yes; mso-bidi-font-size: 12.0pt;">) rownum</span><span style="font-size: 10pt; color: black; font-family: Verdana;"></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt;"><span style="font-size: 10pt; color: gray; font-family: &quot;Courier New&quot;; mso-no-proof: yes; mso-bidi-font-size: 12.0pt;"><span style="mso-spacerun: yes;">      </span>,</span><span style="font-size: 10pt; color: black; font-family: &quot;Courier New&quot;; mso-no-proof: yes; mso-bidi-font-size: 12.0pt;">data_srce_id<br />
</span><span style="font-size: 10pt; color: blue; font-family: &quot;Courier New&quot;; mso-no-proof: yes; mso-bidi-font-size: 12.0pt;">from data_srce </span><span style="font-size: small;"><span style="font-family: Times New Roman;"></code><span style="font-size: 10pt; color: blue; font-family: &quot;Courier New&quot;; mso-no-proof: yes; mso-bidi-font-size: 12.0pt;"></span></span></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt;"><span style="font-size: 10pt; color: blue; font-family: &quot;Courier New&quot;; mso-no-proof: yes; mso-bidi-font-size: 12.0pt;"> </span></p>
<table class="MsoNormalTable" style="margin: auto auto auto 4.65pt; width: 109pt; border-collapse: collapse; mso-padding-alt: 0in 5.4pt 0in 5.4pt;" border="0" cellspacing="0" cellpadding="0" width="145">
<tbody>
<tr style="height: 12.75pt; mso-yfti-irow: 0; mso-yfti-firstrow: yes;">
<td style="padding-right: 5.4pt; padding-left: 5.4pt; padding-bottom: 0in; width: 44pt; padding-top: 0in; height: 12.75pt; background-color: transparent; border: #ece9d8;" width="59" valign="bottom">
<p class="MsoNormal" style="margin: 0in 0in 0pt;"><strong><span style="font-size: 10pt; font-family: Arial;">rownum</span></strong></p>
</td>
<td style="padding-right: 5.4pt; padding-left: 5.4pt; padding-bottom: 0in; width: 65pt; padding-top: 0in; height: 12.75pt; background-color: transparent; border: #ece9d8;" width="87" valign="bottom">
<p class="MsoNormal" style="margin: 0in 0in 0pt;"><strong><span style="font-size: 10pt; font-family: Arial;">data_srce_id</span></strong></p>
</td>
</tr>
<tr style="height: 12.75pt; mso-yfti-irow: 1;">
<td style="padding-right: 5.4pt; padding-left: 5.4pt; padding-bottom: 0in; width: 44pt; padding-top: 0in; height: 12.75pt; background-color: transparent; border: #ece9d8;" width="59" valign="bottom">
<p class="MsoNormal" style="margin: 0in 0in 0pt; text-align: right;" align="right"><span style="font-size: 10pt; font-family: Arial;">1</span></p>
</td>
<td style="padding-right: 5.4pt; padding-left: 5.4pt; padding-bottom: 0in; width: 65pt; padding-top: 0in; height: 12.75pt; background-color: transparent; border: #ece9d8;" width="87" valign="bottom">
<p class="MsoNormal" style="margin: 0in 0in 0pt; text-align: right;" align="right"><span style="font-size: 10pt; font-family: Arial;">8</span></p>
</td>
</tr>
<tr style="height: 12.75pt; mso-yfti-irow: 2;">
<td style="padding-right: 5.4pt; padding-left: 5.4pt; padding-bottom: 0in; width: 44pt; padding-top: 0in; height: 12.75pt; background-color: transparent; border: #ece9d8;" width="59" valign="bottom">
<p class="MsoNormal" style="margin: 0in 0in 0pt; text-align: right;" align="right"><span style="font-size: 10pt; font-family: Arial;">2</span></p>
</td>
<td style="padding-right: 5.4pt; padding-left: 5.4pt; padding-bottom: 0in; width: 65pt; padding-top: 0in; height: 12.75pt; background-color: transparent; border: #ece9d8;" width="87" valign="bottom">
<p class="MsoNormal" style="margin: 0in 0in 0pt; text-align: right;" align="right"><span style="font-size: 10pt; font-family: Arial;">7</span></p>
</td>
</tr>
<tr style="height: 12.75pt; mso-yfti-irow: 3;">
<td style="padding-right: 5.4pt; padding-left: 5.4pt; padding-bottom: 0in; width: 44pt; padding-top: 0in; height: 12.75pt; background-color: transparent; border: #ece9d8;" width="59" valign="bottom">
<p class="MsoNormal" style="margin: 0in 0in 0pt; text-align: right;" align="right"><span style="font-size: 10pt; font-family: Arial;">3</span></p>
</td>
<td style="padding-right: 5.4pt; padding-left: 5.4pt; padding-bottom: 0in; width: 65pt; padding-top: 0in; height: 12.75pt; background-color: transparent; border: #ece9d8;" width="87" valign="bottom">
<p class="MsoNormal" style="margin: 0in 0in 0pt; text-align: right;" align="right"><span style="font-size: 10pt; font-family: Arial;">6</span></p>
</td>
</tr>
<tr style="height: 12.75pt; mso-yfti-irow: 4;">
<td style="padding-right: 5.4pt; padding-left: 5.4pt; padding-bottom: 0in; width: 44pt; padding-top: 0in; height: 12.75pt; background-color: transparent; border: #ece9d8;" width="59" valign="bottom">
<p class="MsoNormal" style="margin: 0in 0in 0pt; text-align: right;" align="right"><span style="font-size: 10pt; font-family: Arial;">4</span></p>
</td>
<td style="padding-right: 5.4pt; padding-left: 5.4pt; padding-bottom: 0in; width: 65pt; padding-top: 0in; height: 12.75pt; background-color: transparent; border: #ece9d8;" width="87" valign="bottom">
<p class="MsoNormal" style="margin: 0in 0in 0pt; text-align: right;" align="right"><span style="font-size: 10pt; font-family: Arial;">5</span></p>
</td>
</tr>
<tr style="height: 12.75pt; mso-yfti-irow: 5;">
<td style="padding-right: 5.4pt; padding-left: 5.4pt; padding-bottom: 0in; width: 44pt; padding-top: 0in; height: 12.75pt; background-color: transparent; border: #ece9d8;" width="59" valign="bottom">
<p class="MsoNormal" style="margin: 0in 0in 0pt; text-align: right;" align="right"><span style="font-size: 10pt; font-family: Arial;">5</span></p>
</td>
<td style="padding-right: 5.4pt; padding-left: 5.4pt; padding-bottom: 0in; width: 65pt; padding-top: 0in; height: 12.75pt; background-color: transparent; border: #ece9d8;" width="87" valign="bottom">
<p class="MsoNormal" style="margin: 0in 0in 0pt; text-align: right;" align="right"><span style="font-size: 10pt; font-family: Arial;">4</span></p>
</td>
</tr>
<tr style="height: 12.75pt; mso-yfti-irow: 6;">
<td style="padding-right: 5.4pt; padding-left: 5.4pt; padding-bottom: 0in; width: 44pt; padding-top: 0in; height: 12.75pt; background-color: transparent; border: #ece9d8;" width="59" valign="bottom">
<p class="MsoNormal" style="margin: 0in 0in 0pt; text-align: right;" align="right"><span style="font-size: 10pt; font-family: Arial;">6</span></p>
</td>
<td style="padding-right: 5.4pt; padding-left: 5.4pt; padding-bottom: 0in; width: 65pt; padding-top: 0in; height: 12.75pt; background-color: transparent; border: #ece9d8;" width="87" valign="bottom">
<p class="MsoNormal" style="margin: 0in 0in 0pt; text-align: right;" align="right"><span style="font-size: 10pt; font-family: Arial;">3</span></p>
</td>
</tr>
<tr style="height: 12.75pt; mso-yfti-irow: 7;">
<td style="padding-right: 5.4pt; padding-left: 5.4pt; padding-bottom: 0in; width: 44pt; padding-top: 0in; height: 12.75pt; background-color: transparent; border: #ece9d8;" width="59" valign="bottom">
<p class="MsoNormal" style="margin: 0in 0in 0pt; text-align: right;" align="right"><span style="font-size: 10pt; font-family: Arial;">7</span></p>
</td>
<td style="padding-right: 5.4pt; padding-left: 5.4pt; padding-bottom: 0in; width: 65pt; padding-top: 0in; height: 12.75pt; background-color: transparent; border: #ece9d8;" width="87" valign="bottom">
<p class="MsoNormal" style="margin: 0in 0in 0pt; text-align: right;" align="right"><span style="font-size: 10pt; font-family: Arial;">2</span></p>
</td>
</tr>
<tr style="height: 12.75pt; mso-yfti-irow: 8;">
<td style="padding-right: 5.4pt; padding-left: 5.4pt; padding-bottom: 0in; width: 44pt; padding-top: 0in; height: 12.75pt; background-color: transparent; border: #ece9d8;" width="59" valign="bottom">
<p class="MsoNormal" style="margin: 0in 0in 0pt; text-align: right;" align="right"><span style="font-size: 10pt; font-family: Arial;">8</span></p>
</td>
<td style="padding-right: 5.4pt; padding-left: 5.4pt; padding-bottom: 0in; width: 65pt; padding-top: 0in; height: 12.75pt; background-color: transparent; border: #ece9d8;" width="87" valign="bottom">
<p class="MsoNormal" style="margin: 0in 0in 0pt; text-align: right;" align="right"><span style="font-size: 10pt; font-family: Arial;">1</span></p>
</td>
</tr>
<tr style="height: 12.75pt; mso-yfti-irow: 9; mso-yfti-lastrow: yes;">
<td style="padding-right: 5.4pt; padding-left: 5.4pt; padding-bottom: 0in; width: 44pt; padding-top: 0in; height: 12.75pt; background-color: transparent; border: #ece9d8;" width="59" valign="bottom">
<p class="MsoNormal" style="margin: 0in 0in 0pt; text-align: right;" align="right"><span style="font-size: 10pt; font-family: Arial;">9</span></p>
</td>
<td style="padding-right: 5.4pt; padding-left: 5.4pt; padding-bottom: 0in; width: 65pt; padding-top: 0in; height: 12.75pt; background-color: transparent; border: #ece9d8;" width="87" valign="bottom">
<p class="MsoNormal" style="margin: 0in 0in 0pt; text-align: right;" align="right"><span style="font-size: 10pt; font-family: Arial;">-1</span></p>
</td>
</tr>
</tbody>
</table>
<p class="MsoNormal" style="margin: 0in 0in 0pt;"><span style="font-size: 10pt; color: black; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><br style="mso-special-character: line-break;" /><br style="mso-special-character: line-break;" /></span><span style="font-size: 7.5pt; color: black; font-family: Verdana;"></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt;"><span style="font-size: 10pt; color: blue; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"> </span><span style="font-size: 7.5pt; color: black; font-family: Verdana;"></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt;"><span style="font-size: small; font-family: Times New Roman;">However, in SQL 2000 it&#8217;s a little more difficult.  The only way I&#8217;ve found is using the IDENTITY() function, which requires an INTO statement, so you pretty much have to load the results into a #temporary table and then select from the #temporary table like this:</span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: small; font-family: Times New Roman;"><code></span><span style="font-size: 10pt; color: blue; font-family: &quot;Courier New&quot;; mso-no-proof: yes;">use</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"> [Database]</span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; color: blue; font-family: &quot;Courier New&quot;; mso-no-proof: yes;">SELECT</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"> <span style="color: blue;">IDENTITY</span><span style="color: gray;">(</span><span style="color: blue;">int</span><span style="color: gray;">,</span> 1<span style="color: gray;">,</span>1<span style="color: gray;">)</span> id</span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;">      </span><span style="color: gray;">,</span>t1<span style="color: gray;">.</span>[column1]<span style="mso-tab-count: 2;">           </span>col1</span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;">      </span><span style="color: gray;">,</span>t1<span style="color: gray;">.</span>[column2]<span style="mso-tab-count: 2;">           </span>col2</span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;">      </span><span style="color: gray;">,</span>t1<span style="color: gray;">.</span>[column3]<span style="mso-tab-count: 2;">           </span>col3</span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;">      </span><span style="color: gray;">,</span>t2<span style="color: gray;">.</span>[column2]<span style="mso-tab-count: 2;">           </span>col4</span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;">  </span><span style="color: blue;">INTO</span> #Temp</span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;">  </span><span style="color: blue;">FROM</span> [dbo]<span style="color: gray;">.</span>[Table] t1</span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span><span style="color: gray;">INNER</span> <span style="color: gray;">JOIN</span> [dbo]<span style="color: gray;">.</span>[Table2] t2</span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;">    </span><span style="color: blue;">ON</span> t<span style="color: gray;">.</span>[column] <span style="color: gray;">=</span> t2<span style="color: gray;">.</span>[column]</span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"> </span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; color: blue; font-family: &quot;Courier New&quot;; mso-no-proof: yes;">select</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"> <span style="color: gray;">*</span> </span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;">  </span><span style="color: blue;">from</span> #Temp</span><span style="font-size: small;"><span style="font-family: Times New Roman;"></code><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"></span></span></span></p>
]]></content:encoded>
			<wfw:commentRss>http://rickcaminiti.com/tips/rownum-equivalent-sql-2000/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>WordPress SEO – Great Tips</title>
		<link>http://rickcaminiti.com/misc/wordpress-seo/</link>
		<comments>http://rickcaminiti.com/misc/wordpress-seo/#comments</comments>
		<pubDate>Mon, 18 May 2009 00:59:26 +0000</pubDate>
		<dc:creator>Rick</dc:creator>
				<category><![CDATA[Misc]]></category>
		<category><![CDATA[Site]]></category>
		<category><![CDATA[Social]]></category>
		<category><![CDATA[Tips]]></category>
		<category><![CDATA[SEO]]></category>
		<category><![CDATA[wordpress]]></category>

		<guid isPermaLink="false">http://rickcaminiti.com/?p=318</guid>
		<description>This is a must-read if you&amp;#8217;re using WordPress and want some SEO tips.  The basic technical optimization: simplest stuff, highest rewards Permalinks Optimize your Titles for SEO Optimize your Descriptions Optimize the More text Image Optimization Template optimization Breadcrumbs Headings Clean up your code Aim for speed Rethink that Sidebar Advanced technical optimization: preventing duplicate [...]</description>
			<content:encoded><![CDATA[<p>This is a must-read if you&#8217;re using WordPress and want some SEO tips. </p>
<ol>
<li><a href="http://rickcaminiti.com/wp-admin/#basicseo"><span style="color: #da3114;">The basic technical optimization</span></a>: simplest stuff, highest rewards</li>
<li><a href="http://rickcaminiti.com/wp-admin/#permalinks"><span style="color: #da3114;">Permalinks</span></a></li>
<li><a href="http://rickcaminiti.com/wp-admin/#titles"><span style="color: #da3114;">Optimize your Titles for SEO</span></a></li>
<li><a href="http://rickcaminiti.com/wp-admin/#descriptions"><span style="color: #da3114;">Optimize your Descriptions</span></a></li>
<li><a href="http://rickcaminiti.com/wp-admin/#moretext"><span style="color: #da3114;">Optimize the More text</span></a></li>
<li><a href="http://rickcaminiti.com/wp-admin/#images"><span style="color: #da3114;">Image Optimization</span></a></li>
<li><a href="http://rickcaminiti.com/wp-admin/#template"><span style="color: #da3114;">Template optimization</span></a></li>
<li><a href="http://rickcaminiti.com/wp-admin/#bread-crumbs"><span style="color: #da3114;">Breadcrumbs</span></a></li>
<li><a href="http://rickcaminiti.com/wp-admin/#headings"><span style="color: #da3114;">Headings</span></a></li>
<li><a href="http://rickcaminiti.com/wp-admin/#codeclean"><span style="color: #da3114;">Clean up your code</span></a></li>
<li><a href="http://rickcaminiti.com/wp-admin/#speed"><span style="color: #da3114;">Aim for speed</span></a></li>
<li><a href="http://rickcaminiti.com/wp-admin/#sidebarthink"><span style="color: #da3114;">Rethink that Sidebar</span></a></li>
<li><a href="http://rickcaminiti.com/wp-admin/#advancedseo"><span style="color: #da3114;">Advanced technical optimization</span></a>: preventing duplicate content</li>
<li><a href="http://rickcaminiti.com/wp-admin/#noindexfollow"><span style="color: #da3114;">Noindex, follow archive pages</span></a></li>
<li><a href="http://rickcaminiti.com/wp-admin/#disablearchives"><span style="color: #da3114;">Disable unnecessary archives</span></a></li>
<li><a href="http://rickcaminiti.com/wp-admin/#pagination"><span style="color: #da3114;">Pagination</span></a></li>
<li><a href="http://rickcaminiti.com/wp-admin/#nofollowmeta"><span style="color: #da3114;">Nofollowing unnecessary links</span></a></li>
<li><a href="http://rickcaminiti.com/wp-admin/#structure"><span style="color: #da3114;">Altering your blog&#8217;s structure for high rankings</span></a></li>
<li><a href="http://rickcaminiti.com/wp-admin/#pagesvsposts"><span style="color: #da3114;">Pages instead of posts</span></a></li>
<li><a href="http://rickcaminiti.com/wp-admin/#newwine"><span style="color: #da3114;">New wine in an old bottle</span></a>: use well ranking-posts to rank even better</li>
<li><a href="http://rickcaminiti.com/wp-admin/#relatedposts"><span style="color: #da3114;">Linking to related posts</span></a></li>
<li><a href="http://rickcaminiti.com/wp-admin/#conversion"><span style="color: #da3114;">Conversion optimization</span></a>: get those readers to subscribe!</li>
<li><a href="http://rickcaminiti.com/wp-admin/#comment"><span style="color: #da3114;">Comment optimization</span></a>: get those readers involved</li>
<li><a href="http://rickcaminiti.com/wp-admin/#ask"><span style="color: #da3114;">How should you get people to comment</span></a></li>
<li><a href="http://rickcaminiti.com/wp-admin/#bond"><span style="color: #da3114;">Bond with your commenters</span></a></li>
<li><a href="http://rickcaminiti.com/wp-admin/#commentsubscribe"><span style="color: #da3114;">Keeping people in the conversation</span></a></li>
<li><a href="http://rickcaminiti.com/wp-admin/#offsite"><span style="color: #da3114;">Off site blog SEO</span></a></li>
<li><a href="http://rickcaminiti.com/wp-admin/#followcomment"><span style="color: #da3114;">Follow your commenters</span></a></li>
<li><a href="http://rickcaminiti.com/wp-admin/#twitter"><span style="color: #da3114;">Use Twitter</span></a></li>
<li><a href="http://rickcaminiti.com/wp-admin/#relatedblogs"><span style="color: #da3114;">Find related blogs, and work them</span></a></li>
<li><a href="http://rickcaminiti.com/wp-admin/#conclusion"><span style="color: #da3114;">Conclusion</span></a></li>
</ol>
]]></content:encoded>
			<wfw:commentRss>http://rickcaminiti.com/misc/wordpress-seo/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Sending Mail with MSSQL</title>
		<link>http://rickcaminiti.com/tips/sending-mail-mssql/</link>
		<comments>http://rickcaminiti.com/tips/sending-mail-mssql/#comments</comments>
		<pubDate>Fri, 15 May 2009 16:13:42 +0000</pubDate>
		<dc:creator>NothingMan</dc:creator>
				<category><![CDATA[BI]]></category>
		<category><![CDATA[Code]]></category>
		<category><![CDATA[Tips]]></category>
		<category><![CDATA[email]]></category>
		<category><![CDATA[microsoft]]></category>
		<category><![CDATA[mssql]]></category>
		<category><![CDATA[sql agent]]></category>
		<category><![CDATA[ssis]]></category>
		<category><![CDATA[t-sql]]></category>

		<guid isPermaLink="false">http://rickcaminiti.com/?p=326</guid>
		<description>Here’s a quick and dirty way to send email via MSSQL.  For some reason, we’re not allowed to send email using the Email Task in SSIS, so I chose this option.  Unfortunately, even if you have access to execute sp_SQLSMTPMail, you might not have access to run xp_cmdshell.   I ended up having to create [...]</description>
			<content:encoded><![CDATA[<p><span style="font-size: 10pt; color: blue; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt;"><span style="font-size: small; color: #000000; font-family: Times New Roman;">Here’s a quick and dirty way to send email via MSSQL.<span style="mso-spacerun: yes;">  </span>For some reason, we’re not allowed to send email using the Email Task in SSIS, so I chose this option.<span style="mso-spacerun: yes;">  </span>Unfortunately, even if you have access to execute sp_SQLSMTPMail, you might not have access to run xp_cmdshell. </span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt;"><span style="font-size: small; color: #000000; font-family: Times New Roman;"> </span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt;"><span style="font-size: small; color: #000000; font-family: Times New Roman;">I ended up having to create my SSIS package with a SQL Task that runs this proc, then I had to run it with a SQL Agent Job with a proxy account that had access to xp_cmdshell.<span style="mso-spacerun: yes;">  </span>Fun stuff.</span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"> </p>
<p></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"> </p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"> </p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"> </p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; color: blue; font-family: &quot;Courier New&quot;; mso-no-proof: yes;">declare</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"> @developerperson <span style="color: blue;">varchar</span><span style="color: gray;">(</span>80<span style="color: gray;">)</span></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; color: blue; font-family: &quot;Courier New&quot;; mso-no-proof: yes;">declare</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"> @message_body <span style="color: blue;">varchar</span><span style="color: gray;">(</span>1000<span style="color: gray;">)</span></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; color: blue; font-family: &quot;Courier New&quot;; mso-no-proof: yes;">set</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"> @message_body <span style="color: gray;">=</span> </span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; color: red; font-family: &quot;Courier New&quot;; mso-no-proof: yes;">&#8216;Dear &#8216;</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"> <span style="color: gray;">+</span> @developerperson <span style="color: gray;">+</span> <span style="color: red;">&#8216;Use \n for line breaks and escape your &#8221;s&#8217;</span></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; color: blue; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="font-size: 10pt; color: blue; font-family: 'Courier New'; mso-no-proof: yes;">EXECUTE</span><span style="font-size: 10pt; font-family: 'Courier New'; mso-no-proof: yes;"><span style="color: #000000;"> </span></span></span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;">dbo<span style="color: gray;">.</span>sp_SQLSMTPMail</span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-tab-count: 1;">      </span>@vcTo <span style="color: gray;">=</span> <span style="color: red;">&#8216;You@you.com&#8217;</span><span style="color: gray;">,</span></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-tab-count: 1;">      </span>@vcCC<span style="color: gray;">=</span> <span style="color: red;">&#8216;Them@them.com&#8217;</span><span style="color: gray;">,</span></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-tab-count: 1;">      </span>@vcSubject <span style="color: gray;">=</span> <span style="color: red;">&#8216;Super Cool SQL Email&#8217;</span><span style="color: gray;">,</span></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-tab-count: 1;">      </span>@vcBody <span style="color: gray;">=</span> @message_body<span style="color: gray;">,</span></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-tab-count: 1;">      </span>@vcFrom <span style="color: gray;">=</span> <span style="color: red;">&#8216;Me@me.com&#8217;</span><span style="color: gray;">,</span></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-tab-count: 1;">      </span>@vcSMTPServer <span style="color: gray;">=</span> <span style="color: red;">&#8216;SMTPName&#8217;</span><span style="color: gray;">,</span></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-tab-count: 1;">      </span>@vcSenderName <span style="color: gray;">=</span> <span style="color: red;">&#8216;Some One&#8217;</span><span style="color: gray;">,</span></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-tab-count: 1;">      </span>@vcServerName <span style="color: gray;">=</span> <span style="color: fuchsia;">@@SERVERNAME</span> <span style="color: green;">&#8211;no need to specify because this is the default anyway</span></span></p>
<p>Or, lets say you want to email query results as an attachment:</p>
<p><span style="font-size: 10pt; color: blue; font-family: 'Courier New'; mso-no-proof: yes;"></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; color: blue; font-family: &quot;Courier New&quot;; mso-no-proof: yes;">EXECUTE</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="color: #000000;"> dbo</span><span style="color: gray;">.</span><span style="color: #000000;">sp_SQLSMTPMail </span></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="color: #000000;"><span style="mso-spacerun: yes;">  </span>@vcTo</span><span style="color: gray;">=</span><span style="color: red;">&#8216;you@you.com&#8217;</span></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; color: gray; font-family: &quot;Courier New&quot;; mso-no-proof: yes;">,</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="color: #000000;"> @vcCC</span><span style="color: gray;">=</span><span style="color: red;">&#8216;them@them.com&#8217;</span></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; color: gray; font-family: &quot;Courier New&quot;; mso-no-proof: yes;">,</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="color: #000000;"> @vcSubject</span><span style="color: gray;">=</span><span style="color: red;">&#8216;Here is your wonderful report that is terribly formatted as a txt file attachment&#8217;</span></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt;"><span style="font-size: 10pt; color: gray; font-family: &quot;Courier New&quot;; mso-no-proof: yes;">,</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="color: #000000;"> @vcquery</span><span style="color: gray;">=</span><span style="color: #000000;"> </span><span style="color: red;">&#8216;select col1, col2, col3, col4 from database.schema.table&#8217;</span></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"> </p>
<p></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p>Here&#8217;s the actual Proc definition:<span id="more-326"></span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"> </span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; color: blue; font-family: &quot;Courier New&quot;; mso-no-proof: yes;">Create</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"> <span style="color: blue;">Procedure</span> dbo<span style="color: gray;">.</span>sp_SQLSMTPMail<span style="mso-spacerun: yes;">  </span></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;">       </span>@vcFrom<span style="mso-spacerun: yes;">         </span><span style="color: blue;">varchar</span><span style="color: gray;">(</span>128<span style="color: gray;">)</span><span style="mso-spacerun: yes;">  </span><span style="color: gray;">=</span> <span style="color: gray;">null,</span></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;">       </span>@vcTo<span style="mso-spacerun: yes;">           </span><span style="color: blue;">varchar</span><span style="color: gray;">(</span>2048<span style="color: gray;">)</span> <span style="color: gray;">=</span> <span style="color: gray;">null,</span> </span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;">       </span>@vcSubject<span style="mso-spacerun: yes;">      </span><span style="color: blue;">varchar</span><span style="color: gray;">(</span>255<span style="color: gray;">)</span><span style="mso-spacerun: yes;">  </span><span style="color: gray;">=</span> <span style="color: gray;">null,</span> </span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;">       </span>@vcBody<span style="mso-spacerun: yes;">         </span><span style="color: blue;">varchar</span><span style="color: gray;">(</span>8000<span style="color: gray;">)</span> <span style="color: gray;">=</span> <span style="color: red;">&#8221;</span><span style="color: gray;">,</span></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;">       </span>@vcCC<span style="mso-spacerun: yes;">           </span><span style="color: blue;">varchar</span><span style="color: gray;">(</span>2048<span style="color: gray;">)</span> <span style="color: gray;">=</span> <span style="color: red;">&#8221;</span><span style="color: gray;">,</span> </span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;">       </span>@vcBCC<span style="mso-spacerun: yes;">          </span><span style="color: blue;">varchar</span><span style="color: gray;">(</span>2048<span style="color: gray;">)</span> <span style="color: gray;">=</span> <span style="color: red;">&#8221;</span><span style="color: gray;">,</span><span style="mso-spacerun: yes;">   </span></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;">       </span>@vcAttachments<span style="mso-spacerun: yes;">  </span><span style="color: blue;">varchar</span><span style="color: gray;">(</span>1024<span style="color: gray;">)</span> <span style="color: gray;">=</span> <span style="color: gray;">null,</span> </span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;">       </span>@vcQuery<span style="mso-spacerun: yes;">        </span><span style="color: blue;">varchar</span><span style="color: gray;">(</span>8000<span style="color: gray;">)</span> <span style="color: gray;">=</span> <span style="color: gray;">null,</span> </span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;">       </span>@vcSMTPServer<span style="mso-spacerun: yes;">   </span><span style="color: blue;">varchar</span><span style="color: gray;">(</span>255<span style="color: gray;">)</span><span style="mso-spacerun: yes;">  </span><span style="color: gray;">=</span> <span style="color: red;">&#8217;192.168.1.55&#8242;</span><span style="color: gray;">,</span><span style="mso-spacerun: yes;">  </span><span style="color: green;">&#8211; PUT YOUR LOCAL SMTP SERVER HERE</span></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;">       </span>@cSendUsing<span style="mso-spacerun: yes;">     </span><span style="color: blue;">char</span><span style="color: gray;">(</span>1<span style="color: gray;">)</span><span style="mso-spacerun: yes;">       </span><span style="color: gray;">=</span> <span style="color: red;">&#8217;2&#8242;</span><span style="color: gray;">,</span> </span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;">       </span>@vcPort<span style="mso-spacerun: yes;">         </span><span style="color: blue;">varchar</span><span style="color: gray;">(</span>3<span style="color: gray;">)</span><span style="mso-spacerun: yes;">    </span><span style="color: gray;">=</span> <span style="color: red;">&#8217;25&#8242;</span><span style="color: gray;">,</span> </span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;">       </span>@cAuthenticate<span style="mso-spacerun: yes;">  </span><span style="color: blue;">char</span><span style="color: gray;">(</span>1<span style="color: gray;">)</span><span style="mso-spacerun: yes;">       </span><span style="color: gray;">=</span> <span style="color: red;">&#8217;0&#8242;</span><span style="color: gray;">,</span> </span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;">       </span>@vcDSNOptions<span style="mso-spacerun: yes;">   </span><span style="color: blue;">varchar</span><span style="color: gray;">(</span>2<span style="color: gray;">)</span><span style="mso-spacerun: yes;">    </span><span style="color: gray;">=</span> <span style="color: red;">&#8217;0&#8242;</span><span style="color: gray;">,</span> </span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;">       </span>@vcTimeout<span style="mso-spacerun: yes;">      </span><span style="color: blue;">varchar</span><span style="color: gray;">(</span>2<span style="color: gray;">)</span><span style="mso-spacerun: yes;">    </span><span style="color: gray;">=</span> <span style="color: red;">&#8217;30&#8242;</span><span style="color: gray;">,</span> </span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;">       </span>@vcSenderName<span style="mso-spacerun: yes;">   </span><span style="color: blue;">varchar</span><span style="color: gray;">(</span>128<span style="color: gray;">)</span><span style="mso-spacerun: yes;">  </span><span style="color: gray;">=</span> <span style="color: gray;">null,</span> </span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;">       </span>@vcServerName<span style="mso-spacerun: yes;">   </span><span style="color: blue;">sysname</span><span style="mso-spacerun: yes;">       </span><span style="color: gray;">=</span> <span style="color: gray;">null</span> </span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; color: blue; font-family: &quot;Courier New&quot;; mso-no-proof: yes;">As</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"> </span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; color: blue; font-family: &quot;Courier New&quot;; mso-no-proof: yes;">Set</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"> <span style="color: blue;">nocount</span> <span style="color: blue;">on</span> </span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; color: green; font-family: &quot;Courier New&quot;; mso-no-proof: yes;">&#8211; Determine if the user requested syntax. </span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; color: blue; font-family: &quot;Courier New&quot;; mso-no-proof: yes;">If</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"> @vcTo <span style="color: gray;">=</span> <span style="color: red;">&#8216;?&#8217;</span> </span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;">   </span><span style="color: blue;">Begin</span> </span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;">      </span><span style="color: blue;">Print</span> <span style="color: red;">&#8216;Syntax for sp_SQLSMTPMail (based on CDOSYS):&#8217;</span> </span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;">      </span><span style="color: blue;">Print</span> <span style="color: red;">&#8216;Exec master.dbo.sp_SQLSMTPMail&#8217;</span> </span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;">      </span><span style="color: blue;">Print</span> <span style="color: red;">&#8216;<span style="mso-spacerun: yes;">     </span>@vcTo<span style="mso-spacerun: yes;">          </span>(varchar(2048)) &#8211; Recipient e-mail address list separating each with a &#8221;;&#8221; &#8216;</span> </span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;">      </span><span style="color: blue;">Print</span> <span style="color: red;">&#8216;<span style="mso-spacerun: yes;">                                       </span>or a &#8221;,&#8221;. Use a &#8221;?&#8221; to return the syntax.&#8217;</span> </span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;">      </span><span style="color: blue;">Print</span> <span style="color: red;">&#8216;<span style="mso-spacerun: yes;">     </span>@vcBody<span style="mso-spacerun: yes;">        </span>(varchar(8000)) &#8211; Text body; use embedded char(13) + char(10)&#8217;</span> </span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;">      </span><span style="color: blue;">Print</span> <span style="color: red;">&#8216;<span style="mso-spacerun: yes;">                                       </span>for carriage returns. The default is nothing&#8217;</span> </span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;">      </span><span style="color: blue;">Print</span> <span style="color: red;">&#8216;<span style="mso-spacerun: yes;">     </span>@vcSubject<span style="mso-spacerun: yes;">     </span>(varchar(255))) &#8211; E-mail subject. The default is a message from&#8217;</span> </span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;">      </span><span style="color: blue;">Print</span> <span style="color: red;">&#8216;<span style="mso-spacerun: yes;">  </span><span style="mso-spacerun: yes;">                                     </span>@@servername.&#8217;</span> </span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;">      </span><span style="color: blue;">Print</span> <span style="color: red;">&#8216;<span style="mso-spacerun: yes;">     </span>@vcAttachments (varchar(1024)) &#8211; Attachment list separating each with a &#8221;;&#8221;.&#8217;</span> </span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;">      </span><span style="color: blue;">Print</span> <span style="color: red;">&#8216;<span style="mso-spacerun: yes;">                                       </span>The default is no attachments.&#8217;</span> </span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;">      </span><span style="color: blue;">Print</span> <span style="color: red;">&#8216;<span style="mso-spacerun: yes;">     </span>@vcQuery<span style="mso-spacerun: yes;">       </span>(varchar(8000)) &#8211; In-line query or a query file path; do not &#8216;</span> </span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;">      </span><span style="color: blue;">Print</span> <span style="color: red;">&#8216;<span style="mso-spacerun: yes;">                                       </span>use double quotes within the query.&#8217;</span> </span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;">      </span><span style="color: blue;">Print</span> <span style="color: red;">&#8216;<span style="mso-spacerun: yes;">     </span>@vcFrom<span style="mso-spacerun: yes;">        </span>(varchar(128))<span style="mso-spacerun: yes;">  </span>- Sender list defaulted to @@ServerName.&#8217;</span> </span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;">      </span><span style="color: blue;">Print</span> <span style="color: red;">&#8216;<span style="mso-spacerun: yes;">     </span>@vcCC<span style="mso-spacerun: yes;">          </span>(varchar(2048)) &#8211; CC list separating each with a &#8221;;&#8221; or a &#8221;,&#8221;&#8217;</span> </span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;">      </span><span style="color: blue;">Print</span> <span style="color: red;">&#8216;<span style="mso-spacerun: yes;">                                       </span>The default is no CC addresses.&#8217;</span> </span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;">      </span><span style="color: blue;">Print</span> <span style="color: red;">&#8216;<span style="mso-spacerun: yes;">     </span>@vcBCC<span style="mso-spacerun: yes;">         </span>(varchar(2048)) &#8211; Blind CC list separating each with a &#8221;;&#8221; or a &#8221;,&#8221;&#8217;</span> </span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;">      </span><span style="color: blue;">Print</span> <span style="color: red;">&#8216;<span style="mso-spacerun: yes;">                                       </span>The default is no BCC addresses.&#8217;</span> </span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;">      </span><span style="color: blue;">Print</span> <span style="color: red;">&#8216;<span style="mso-spacerun: yes;">     </span>@vcSMTPServer<span style="mso-spacerun: yes;">  </span>(varchar(255))<span style="mso-spacerun: yes;">  </span>- Network smtp server defaulted to your companies network&#8217;</span> </span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span><span style="color: blue;">Print</span> <span style="color: red;">&#8216;<span style="mso-spacerun: yes;">                                       </span>smtp server. Set this in the stored proc code.&#8217;</span> </span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;">      </span><span style="color: blue;">Print</span> <span style="color: red;">&#8216;<span style="mso-spacerun: yes;">     </span>@cSendUsing<span style="mso-spacerun: yes;">    </span>(char(1))<span style="mso-spacerun: yes;">       </span>- Specifies the smpt server method, local or network. The&#8217;</span> </span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;">      </span><span style="color: blue;">Print</span> <span style="color: red;">&#8216;<span style="mso-spacerun: yes;">                                       </span>default is network, a value of &#8221;2&#8221;.&#8217;</span> </span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;">      </span><span style="color: blue;">Print</span> <span style="color: red;">&#8216;<span style="mso-spacerun: yes;">     </span>@vcPort<span style="mso-spacerun: yes;">        </span>(varchar(3))<span style="mso-spacerun: yes;">    </span>- The smtp server communication port defaulted to &#8221;25&#8221;.&#8217;</span> </span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;">      </span><span style="color: blue;">Print</span> <span style="color: red;">&#8216;<span style="mso-spacerun: yes;">     </span>@cAuthenticate (char(1))<span style="mso-spacerun: yes;">       </span>- The smtp server authentication method defaulted to &#8216;</span> </span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;">      </span><span style="color: blue;">Print</span> <span style="color: red;">&#8216;<span style="mso-spacerun: yes;">                                       </span>anonymous, a value of &#8221;0&#8221;.&#8217;</span> </span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;">      </span><span style="color: blue;">Print</span> <span style="color: red;">&#8216;<span style="mso-spacerun: yes;">     </span>@vcDSNOptions<span style="mso-spacerun: yes;">  </span>(varchar(2))<span style="mso-spacerun: yes;">    </span>- The smtp server delivery status defaulted to none,&#8217;</span> </span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;">      </span><span style="color: blue;">Print</span> <span style="color: red;">&#8216;<span style="mso-spacerun: yes;">                  </span><span style="mso-spacerun: yes;">                     </span>a value of &#8221;0&#8221;.&#8217;</span> </span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;">      </span><span style="color: blue;">Print</span> <span style="color: red;">&#8216;<span style="mso-spacerun: yes;">     </span>@vcTimeout<span style="mso-spacerun: yes;">     </span>(varchar(2))<span style="mso-spacerun: yes;">    </span>- The smtp server connection timeout defaulted to 30 seconds.&#8217;</span> </span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;">      </span><span style="color: blue;">Print</span> <span style="color: red;">&#8216;<span style="mso-spacerun: yes;">     </span>@vcSenderName<span style="mso-spacerun: yes;">  </span>(varchar(128))<span style="mso-spacerun: yes;">  </span>- Primary sender name defaulted to @@ServerName.&#8217;</span> </span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;">  </span><span style="mso-spacerun: yes;">    </span><span style="color: blue;">Print</span> <span style="color: red;">&#8216;<span style="mso-spacerun: yes;">     </span>@vcServerName<span style="mso-spacerun: yes;">  </span>(sysname)<span style="mso-spacerun: yes;">       </span>- SQL Server to which the query is directed defaulted&#8217;</span> </span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;">      </span><span style="color: blue;">Print</span> <span style="color: red;">&#8216;<span style="mso-spacerun: yes;">                                       </span>to @@ServerName.&#8217;</span> </span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;">      </span><span style="color: blue;">Print</span> <span style="color: red;">&#8221;</span> </span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;">      </span><span style="color: blue;">Print</span> <span style="color: red;">&#8221;</span> </span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;">      </span><span style="color: blue;">Print</span> <span style="color: red;">&#8216;Example:&#8217;</span> </span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;">      </span><span style="color: blue;">Print</span> <span style="color: red;">&#8216;sp_SQLSMTPMail &#8221;&lt;user@mycompany.com&gt;&#8221;, &#8221;This is a test&#8221;, @vcSMTPServer = &lt;network smtp relay server&gt;&#8217;</span> </span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;">      </span><span style="color: blue;">Print</span> <span style="color: red;">&#8221;</span> </span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;">      </span><span style="color: blue;">Print</span> <span style="color: red;">&#8216;The above example will send an smpt e-mail to &lt;user@mycompany.com&gt; from @@ServerName&#8217;</span> </span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;">      </span><span style="color: blue;">Print</span> <span style="color: red;">&#8216;with a subject of &#8221;Message from SQL Server &lt;@@ServerName&gt;&#8221; and a&#8217;</span> </span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;">      </span><span style="color: blue;">Print</span> <span style="color: red;">&#8216;text body of &#8221;This is a test&#8221; using the network smtp server specified.&#8217;</span> </span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;">      </span><span style="color: blue;">Print</span> <span style="color: red;">&#8216;See the MSDN online library, Messaging and Collaboration, at &#8216;</span> </span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;">      </span><span style="color: blue;">Print</span> <span style="color: red;">&#8216;http://www.msdn.microsoft.com/library/ for details about CDOSYS.&#8217;</span> </span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;">      </span><span style="color: blue;">Print</span> <span style="color: red;">&#8216;subheadings: Messaging and Collaboration&gt;Collaboration Data Objects&gt;CDO for Windows 2000&gt;&#8217;</span> </span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;">      </span><span style="color: blue;">Print</span> <span style="color: red;">&#8216;Reference&gt;Fields&gt;http://schemas.microsoft.com/cdo/configuration/&gt;smtpserver field&#8217;</span> </span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;">      </span><span style="color: blue;">Print</span> <span style="color: red;">&#8221;</span> </span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;">      </span><span style="color: blue;">Print</span> <span style="color: red;">&#8216;Be sure to set the default for @vcSMTPServer before compiling this stored procedure.&#8217;</span> </span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;">      </span><span style="color: blue;">Print</span> <span style="color: red;">&#8221;</span> </span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;">      </span><span style="color: blue;">Return</span> </span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;">   </span><span style="color: blue;">End</span> </span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; color: green; font-family: &quot;Courier New&quot;; mso-no-proof: yes;">&#8211; Declare variables </span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; color: blue; font-family: &quot;Courier New&quot;; mso-no-proof: yes;">Declare</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"> @iMessageObjId<span style="mso-spacerun: yes;">    </span><span style="color: blue;">int</span> </span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; color: blue; font-family: &quot;Courier New&quot;; mso-no-proof: yes;">Declare</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"> @iHr<span style="mso-spacerun: yes;">              </span><span style="color: blue;">int</span> </span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; color: blue; font-family: &quot;Courier New&quot;; mso-no-proof: yes;">Declare</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"> @iRtn<span style="mso-spacerun: yes;">             </span><span style="color: blue;">int</span> </span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; color: blue; font-family: &quot;Courier New&quot;; mso-no-proof: yes;">Declare</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"> @iFileExists<span style="mso-spacerun: yes;">      </span><span style="color: blue;">tinyint</span> </span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; color: blue; font-family: &quot;Courier New&quot;; mso-no-proof: yes;">Declare</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"> @vcCmd<span style="mso-spacerun: yes;">            </span><span style="color: blue;">varchar</span><span style="color: gray;">(</span>255<span style="color: gray;">)</span> </span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; color: blue; font-family: &quot;Courier New&quot;; mso-no-proof: yes;">Declare</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"> @vcQueryOutPath<span style="mso-spacerun: yes;">   </span><span style="color: blue;">varchar</span><span style="color: gray;">(</span>50<span style="color: gray;">)</span> </span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; color: blue; font-family: &quot;Courier New&quot;; mso-no-proof: yes;">Declare</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"> @dtDatetime<span style="mso-spacerun: yes;">       </span><span style="color: blue;">datetime</span> </span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; color: blue; font-family: &quot;Courier New&quot;; mso-no-proof: yes;">Declare</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"> @vcErrMssg<span style="mso-spacerun: yes;">        </span><span style="color: blue;">varchar</span><span style="color: gray;">(</span>255<span style="color: gray;">)</span> </span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; color: blue; font-family: &quot;Courier New&quot;; mso-no-proof: yes;">Declare</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"> @vcAttachment<span style="mso-spacerun: yes;">     </span><span style="color: blue;">varchar</span><span style="color: gray;">(</span>1024<span style="color: gray;">)</span> </span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; color: blue; font-family: &quot;Courier New&quot;; mso-no-proof: yes;">Declare</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"> @iPos<span style="mso-spacerun: yes;">             </span><span style="color: blue;">int</span> </span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; color: blue; font-family: &quot;Courier New&quot;; mso-no-proof: yes;">Declare</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"> @vcErrSource<span style="mso-spacerun: yes;">      </span><span style="color: blue;">varchar</span><span style="color: gray;">(</span>255<span style="color: gray;">)</span> </span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; color: blue; font-family: &quot;Courier New&quot;; mso-no-proof: yes;">Declare</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"> @vcErrDescription <span style="color: blue;">varchar</span><span style="color: gray;">(</span>255<span style="color: gray;">)</span> </span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; color: green; font-family: &quot;Courier New&quot;; mso-no-proof: yes;">&#8211; Set local variables. </span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; color: blue; font-family: &quot;Courier New&quot;; mso-no-proof: yes;">Set</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"> @dtDatetime <span style="color: gray;">=</span> <span style="color: fuchsia;">getdate</span><span style="color: gray;">()</span> </span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; color: blue; font-family: &quot;Courier New&quot;; mso-no-proof: yes;">Set</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"> @iHr <span style="color: gray;">=</span> 0 </span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; color: green; font-family: &quot;Courier New&quot;; mso-no-proof: yes;">&#8211; Check for minimum parameters. </span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; color: blue; font-family: &quot;Courier New&quot;; mso-no-proof: yes;">If</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"> @vcTo <span style="color: gray;">is</span> <span style="color: gray;">null</span> </span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;">   </span><span style="color: blue;">Begin</span> </span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;">      </span><span style="color: blue;">Set</span> @vcErrMssg <span style="color: gray;">=</span> <span style="color: red;">&#8216;You must supply at least 1 recipient.&#8217;</span> </span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;">      </span><span style="color: blue;">Goto</span> ErrMssg </span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;">   </span><span style="color: blue;">End</span><span style="mso-spacerun: yes;">  </span></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; color: green; font-family: &quot;Courier New&quot;; mso-no-proof: yes;">&#8211; CDOSYS uses commas to separate recipients. Allow users to use<span style="mso-spacerun: yes;">   </span></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; color: green; font-family: &quot;Courier New&quot;; mso-no-proof: yes;">&#8211; either a comma or a semi-colon by replacing semi-colons in the<span style="mso-spacerun: yes;">  </span></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; color: green; font-family: &quot;Courier New&quot;; mso-no-proof: yes;">&#8211; To, CCs and BCCs. </span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; color: blue; font-family: &quot;Courier New&quot;; mso-no-proof: yes;">Select</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"> @vcTo <span style="color: gray;">=</span> <span style="color: fuchsia;">Replace</span><span style="color: gray;">(</span>@vcTo<span style="color: gray;">,</span> <span style="color: red;">&#8216;;&#8217;</span><span style="color: gray;">,</span> <span style="color: red;">&#8216;,&#8217;</span><span style="color: gray;">)</span> </span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; color: blue; font-family: &quot;Courier New&quot;; mso-no-proof: yes;">Select</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"> @vcCC <span style="color: gray;">=</span> <span style="color: fuchsia;">Replace</span><span style="color: gray;">(</span>@vcCC<span style="color: gray;">,</span> <span style="color: red;">&#8216;;&#8217;</span><span style="color: gray;">,</span> <span style="color: red;">&#8216;,&#8217;</span><span style="color: gray;">)</span> </span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; color: blue; font-family: &quot;Courier New&quot;; mso-no-proof: yes;">Select</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"> @vcBCC <span style="color: gray;">=</span> <span style="color: fuchsia;">Replace</span><span style="color: gray;">(</span>@vcBCC<span style="color: gray;">,</span> <span style="color: red;">&#8216;;&#8217;</span><span style="color: gray;">,</span> <span style="color: red;">&#8216;,&#8217;</span><span style="color: gray;">)</span> </span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; color: green; font-family: &quot;Courier New&quot;; mso-no-proof: yes;">&#8211; Set the default SQL Server to the local SQL Server if one<span style="mso-spacerun: yes;">   </span></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; color: green; font-family: &quot;Courier New&quot;; mso-no-proof: yes;">&#8211; is not provided to accommodate instances in SQL 2000. </span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; color: blue; font-family: &quot;Courier New&quot;; mso-no-proof: yes;">If</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"> @vcServerName <span style="color: gray;">is</span> <span style="color: gray;">null</span> </span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;">   </span><span style="color: blue;">Set</span> @vcServerName <span style="color: gray;">=</span> <span style="color: fuchsia;">@@servername</span> </span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; color: green; font-family: &quot;Courier New&quot;; mso-no-proof: yes;">&#8211; Set a default &#8220;subject&#8221; if one is not provided. </span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; color: blue; font-family: &quot;Courier New&quot;; mso-no-proof: yes;">If</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"> @vcSubject <span style="color: gray;">is</span> <span style="color: gray;">null</span> </span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;">   </span><span style="color: blue;">Set</span> @vcSubject <span style="color: gray;">=</span> <span style="color: red;">&#8216;Message from SQL Server &#8216;</span> <span style="color: gray;">+</span> @vcServerName </span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; color: green; font-family: &quot;Courier New&quot;; mso-no-proof: yes;">&#8211; Set a default &#8220;from&#8221; if one is not provided. </span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; color: blue; font-family: &quot;Courier New&quot;; mso-no-proof: yes;">If</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"> @vcFrom <span style="color: gray;">is</span> <span style="color: gray;">null</span> </span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;">   </span><span style="color: blue;">Set</span> @vcFrom <span style="color: gray;">=</span> <span style="color: red;">&#8216;SQL-&#8217;</span> <span style="color: gray;">+</span> <span style="color: fuchsia;">Replace</span><span style="color: gray;">(</span>@vcServerName<span style="color: gray;">,</span><span style="color: red;">&#8216;\&#8217;</span><span style="color: gray;">,</span><span style="color: red;">&#8216;_&#8217;</span><span style="color: gray;">)</span> </span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; color: green; font-family: &quot;Courier New&quot;; mso-no-proof: yes;">&#8211; Set a default &#8220;sender name&#8221; if one is not provided. </span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; color: blue; font-family: &quot;Courier New&quot;; mso-no-proof: yes;">If</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"> @vcSenderName <span style="color: gray;">is</span> <span style="color: gray;">null</span> </span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;">   </span><span style="color: blue;">Set</span> @vcSenderName <span style="color: gray;">=</span> <span style="color: red;">&#8216;SQL-&#8217;</span> <span style="color: gray;">+</span> <span style="color: fuchsia;">Replace</span><span style="color: gray;">(</span>@vcServerName<span style="color: gray;">,</span><span style="color: red;">&#8216;\&#8217;</span><span style="color: gray;">,</span><span style="color: red;">&#8216;_&#8217;</span><span style="color: gray;">)</span> </span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; color: green; font-family: &quot;Courier New&quot;; mso-no-proof: yes;">&#8211; Create the SMTP message object. </span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; color: blue; font-family: &quot;Courier New&quot;; mso-no-proof: yes;">EXEC</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"> @iHr <span style="color: gray;">=</span> sp_OACreate <span style="color: red;">&#8216;CDO.Message&#8217;</span><span style="color: gray;">,</span> @iMessageObjId <span style="color: blue;">OUT</span> </span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; color: blue; font-family: &quot;Courier New&quot;; mso-no-proof: yes;">IF</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"> @iHr <span style="color: gray;">&lt;&gt;</span> 0<span style="mso-spacerun: yes;">  </span></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;">   </span><span style="color: blue;">Begin</span> </span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;">   </span><span style="color: blue;">Set</span> @vcErrMssg <span style="color: gray;">=</span> <span style="color: red;">&#8216;Error creating object CDO.Message.&#8217;</span> </span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;">      </span><span style="color: blue;">Goto</span> ErrMssg<span style="mso-spacerun: yes;">  </span></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;">   </span><span style="color: blue;">End</span> </span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; color: green; font-family: &quot;Courier New&quot;; mso-no-proof: yes;">&#8211; Set SMTP message object parameters. </span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; color: green; font-family: &quot;Courier New&quot;; mso-no-proof: yes;">&#8211; To </span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; color: blue; font-family: &quot;Courier New&quot;; mso-no-proof: yes;">EXEC</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"> @iHr <span style="color: gray;">=</span> sp_OASetProperty @iMessageObjId<span style="color: gray;">,</span> <span style="color: red;">&#8216;To&#8217;</span><span style="color: gray;">,</span> @vcTo </span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; color: blue; font-family: &quot;Courier New&quot;; mso-no-proof: yes;">IF</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"> @iHr <span style="color: gray;">&lt;&gt;</span> 0<span style="mso-spacerun: yes;">  </span></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;">   </span><span style="color: blue;">Begin</span><span style="mso-spacerun: yes;">  </span></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;">      </span><span style="color: blue;">Set</span> @vcErrMssg <span style="color: gray;">=</span> <span style="color: red;">&#8216;Error setting Message parameter &#8220;To&#8221;.&#8217;</span> </span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;">    </span><span style="color: blue;">Goto</span> ErrMssg<span style="mso-spacerun: yes;">  </span></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;">   </span><span style="color: blue;">End</span> </span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; color: green; font-family: &quot;Courier New&quot;; mso-no-proof: yes;">&#8211; Subject </span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; color: blue; font-family: &quot;Courier New&quot;; mso-no-proof: yes;">EXEC</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"> @iHr <span style="color: gray;">=</span> sp_OASetProperty @iMessageObjId<span style="color: gray;">,</span> <span style="color: red;">&#8216;Subject&#8217;</span><span style="color: gray;">,</span> @vcSubject </span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; color: blue; font-family: &quot;Courier New&quot;; mso-no-proof: yes;">IF</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"> @iHr <span style="color: gray;">&lt;&gt;</span> 0<span style="mso-spacerun: yes;">  </span></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;">   </span><span style="color: blue;">Begin</span><span style="mso-spacerun: yes;">  </span></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;">      </span><span style="color: blue;">Set</span> @vcErrMssg <span style="color: gray;">=</span> <span style="color: red;">&#8216;Error setting Message parameter &#8220;Subject&#8221;.&#8217;</span> </span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;">      </span><span style="color: blue;">Goto</span> ErrMssg<span style="mso-spacerun: yes;">  </span></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;">   </span><span style="color: blue;">End</span> </span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; color: green; font-family: &quot;Courier New&quot;; mso-no-proof: yes;">&#8211; From </span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; color: blue; font-family: &quot;Courier New&quot;; mso-no-proof: yes;">EXEC</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"> @iHr <span style="color: gray;">=</span> sp_OASetProperty @iMessageObjId<span style="color: gray;">,</span> <span style="color: red;">&#8216;From&#8217;</span><span style="color: gray;">,</span> @vcFrom </span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; color: blue; font-family: &quot;Courier New&quot;; mso-no-proof: yes;">IF</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"> @iHr <span style="color: gray;">&lt;&gt;</span> 0<span style="mso-spacerun: yes;">  </span></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;">   </span><span style="color: blue;">Begin</span><span style="mso-spacerun: yes;">  </span></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;">      </span><span style="color: blue;">Set</span> @vcErrMssg <span style="color: gray;">=</span> <span style="color: red;">&#8216;Error setting Message parameter &#8220;From&#8221;.&#8217;</span> </span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;">      </span><span style="color: blue;">Goto</span> ErrMssg<span style="mso-spacerun: yes;">  </span></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;">   </span><span style="color: blue;">End</span> </span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; color: green; font-family: &quot;Courier New&quot;; mso-no-proof: yes;">&#8211; CC </span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; color: blue; font-family: &quot;Courier New&quot;; mso-no-proof: yes;">EXEC</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"> @iHr <span style="color: gray;">=</span> sp_OASetProperty @iMessageObjId<span style="color: gray;">,</span> <span style="color: red;">&#8216;CC&#8217;</span><span style="color: gray;">,</span> @vcCC </span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; color: blue; font-family: &quot;Courier New&quot;; mso-no-proof: yes;">IF</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"> @iHr <span style="color: gray;">&lt;&gt;</span> 0<span style="mso-spacerun: yes;">  </span></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;">   </span><span style="color: blue;">Begin</span><span style="mso-spacerun: yes;">  </span></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;">      </span><span style="color: blue;">Set</span> @vcErrMssg <span style="color: gray;">=</span> <span style="color: red;">&#8216;Error setting Message parameter &#8220;CC&#8221;.&#8217;</span> </span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;">      </span><span style="color: blue;">Goto</span> ErrMssg<span style="mso-spacerun: yes;">  </span></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;">   </span><span style="color: blue;">End</span> </span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; color: green; font-family: &quot;Courier New&quot;; mso-no-proof: yes;">&#8211; BCC </span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; color: blue; font-family: &quot;Courier New&quot;; mso-no-proof: yes;">EXEC</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"> @iHr <span style="color: gray;">=</span> sp_OASetProperty @iMessageObjId<span style="color: gray;">,</span> <span style="color: red;">&#8216;BCC&#8217;</span><span style="color: gray;">,</span> @vcBCC </span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; color: blue; font-family: &quot;Courier New&quot;; mso-no-proof: yes;">IF</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"> @iHr <span style="color: gray;">&lt;&gt;</span> 0<span style="mso-spacerun: yes;">  </span></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;">   </span><span style="color: blue;">Begin</span><span style="mso-spacerun: yes;">  </span></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;">      </span><span style="color: blue;">Set</span> @vcErrMssg <span style="color: gray;">=</span> <span style="color: red;">&#8216;Error setting Message parameter &#8220;BCC&#8221;.&#8217;</span> </span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;">      </span><span style="color: blue;">Goto</span> ErrMssg<span style="mso-spacerun: yes;">  </span></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;">   </span><span style="color: blue;">End</span> </span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; color: green; font-family: &quot;Courier New&quot;; mso-no-proof: yes;">&#8211; DSNOptions </span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; color: blue; font-family: &quot;Courier New&quot;; mso-no-proof: yes;">EXEC</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"> @iHr <span style="color: gray;">=</span> sp_OASetProperty @iMessageObjId<span style="color: gray;">,</span> <span style="color: red;">&#8216;DSNOptions&#8217;</span><span style="color: gray;">,</span> @vcDSNOptions </span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; color: blue; font-family: &quot;Courier New&quot;; mso-no-proof: yes;">IF</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"> @iHr <span style="color: gray;">&lt;&gt;</span> 0<span style="mso-spacerun: yes;">  </span></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;">   </span><span style="color: blue;">Begin</span><span style="mso-spacerun: yes;">  </span></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;">      </span><span style="color: blue;">Set</span> @vcErrMssg <span style="color: gray;">=</span> <span style="color: red;">&#8216;Error setting Message parameter &#8220;DSNOptions&#8221;.&#8217;</span> </span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;">      </span><span style="color: blue;">Goto</span> ErrMssg<span style="mso-spacerun: yes;">  </span></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;">   </span><span style="color: blue;">End</span> </span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; color: green; font-family: &quot;Courier New&quot;; mso-no-proof: yes;">&#8211; Sender </span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; color: blue; font-family: &quot;Courier New&quot;; mso-no-proof: yes;">EXEC</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"> @iHr <span style="color: gray;">=</span> sp_OASetProperty @iMessageObjId<span style="color: gray;">,</span> <span style="color: red;">&#8216;Sender&#8217;</span><span style="color: gray;">,</span> @vcSenderName </span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; color: blue; font-family: &quot;Courier New&quot;; mso-no-proof: yes;">IF</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"> @iHr <span style="color: gray;">&lt;&gt;</span> 0<span style="mso-spacerun: yes;">  </span></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;">   </span><span style="color: blue;">Begin</span><span style="mso-spacerun: yes;">  </span></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;">      </span><span style="color: blue;">Set</span> @vcErrMssg <span style="color: gray;">=</span> <span style="color: red;">&#8216;Error setting Message parameter &#8220;Sender&#8221;.&#8217;</span> </span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;">      </span><span style="color: blue;">Goto</span> ErrMssg<span style="mso-spacerun: yes;">  </span></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;">   </span><span style="color: blue;">End</span> </span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; color: green; font-family: &quot;Courier New&quot;; mso-no-proof: yes;">&#8211; Is there a query to run? </span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; color: blue; font-family: &quot;Courier New&quot;; mso-no-proof: yes;">If</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"> @vcQuery <span style="color: gray;">is</span> <span style="color: gray;">not</span> <span style="color: gray;">null</span> <span style="color: gray;">and</span> @vcQuery <span style="color: gray;">&lt;&gt;</span> <span style="color: red;">&#8221;</span> </span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;">   </span><span style="color: blue;">Begin</span> </span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;">      </span><span style="color: green;">&#8211; We have a query result to include; temporarily send the output to the<span style="mso-spacerun: yes;">  </span></span></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;">      </span><span style="color: green;">&#8211; drive with the most free space. Use xp_fixeddrives to determine this. </span></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;">      </span><span style="color: green;">&#8211; If a temp table exists with the following name drop it. </span></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;">      </span><span style="color: blue;">If</span> <span style="color: gray;">(</span><span style="color: blue;">Select</span> <span style="color: fuchsia;">object_id</span><span style="color: gray;">(</span><span style="color: red;">&#8216;tempdb.dbo.#fixeddrives&#8217;</span><span style="color: gray;">))</span> <span style="color: gray;">&gt;</span> 0 </span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;">         </span><span style="color: blue;">Exec</span> <span style="color: gray;">(</span><span style="color: red;">&#8216;Drop table #fixeddrives&#8217;</span><span style="color: gray;">)</span> </span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;">       </span></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;">      </span><span style="color: green;">&#8211; Create a temp table to work with xp_fixeddrives. </span></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;">      </span><span style="color: blue;">Create</span> <span style="color: blue;">table</span> #fixeddrives<span style="color: gray;">(</span> </span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;">             </span>Drive <span style="color: blue;">char</span><span style="color: gray;">(</span>1<span style="color: gray;">)</span> <span style="color: gray;">null,</span> </span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;">             </span>FreeSpace<span style="mso-spacerun: yes;">  </span><span style="color: blue;">varchar</span><span style="color: gray;">(</span>15<span style="color: gray;">)</span> <span style="color: gray;">null)</span> </span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;">      </span><span style="color: green;">&#8211; Get the fixeddrive info. </span></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;">      </span><span style="color: blue;">Insert</span> <span style="color: blue;">into</span> #fixeddrives <span style="color: blue;">Exec</span> master<span style="color: gray;">.</span>dbo<span style="color: gray;">.</span>xp_fixeddrives </span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;">      </span><span style="color: green;">&#8211; Get the drive letter of the drive with the most free space </span></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;">      </span><span style="color: green;">&#8211; Note: The OSQL output file name must be unique for each call within the same session. </span></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;">      </span><span style="color: green;">&#8211;<span style="mso-spacerun: yes;">       </span>Apparently OSQL does not release its lock on the first file created until the session ends. </span></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;">      </span><span style="color: green;">&#8211;<span style="mso-spacerun: yes;">       </span>Hence this alleviates a problem with queries from multiple calls in a cursor or other loop. </span></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;">      </span><span style="color: blue;">Select</span> @vcQueryOutPath <span style="color: gray;">=</span> Drive <span style="color: gray;">+</span> <span style="color: red;">&#8216;:\TempQueryOut&#8217;</span> <span style="color: gray;">+</span><span style="mso-spacerun: yes;">  </span></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;">                               </span><span style="color: fuchsia;">ltrim</span><span style="color: gray;">(</span><span style="color: fuchsia;">str</span><span style="color: gray;">(</span><span style="color: fuchsia;">datepart</span><span style="color: gray;">(</span>hh<span style="color: gray;">,</span><span style="color: fuchsia;">getdate</span><span style="color: gray;">())))</span> <span style="color: gray;">+</span><span style="mso-spacerun: yes;">  </span></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;">                               </span><span style="color: fuchsia;">ltrim</span><span style="color: gray;">(</span><span style="color: fuchsia;">str</span><span style="color: gray;">(</span><span style="color: fuchsia;">datepart</span><span style="color: gray;">(</span>mi<span style="color: gray;">,</span><span style="color: fuchsia;">getdate</span><span style="color: gray;">())))</span> <span style="color: gray;">+</span><span style="mso-spacerun: yes;">  </span></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;">                               </span><span style="color: fuchsia;">ltrim</span><span style="color: gray;">(</span><span style="color: fuchsia;">str</span><span style="color: gray;">(</span><span style="color: fuchsia;">datepart</span><span style="color: gray;">(</span>ss<span style="color: gray;">,</span><span style="color: fuchsia;">getdate</span><span style="color: gray;">())))</span> <span style="color: gray;">+</span> </span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;">                               </span><span style="color: fuchsia;">ltrim</span><span style="color: gray;">(</span><span style="color: fuchsia;">str</span><span style="color: gray;">(</span><span style="color: fuchsia;">datepart</span><span style="color: gray;">(</span>ms<span style="color: gray;">,</span><span style="color: fuchsia;">getdate</span><span style="color: gray;">())))</span> <span style="color: gray;">+</span> <span style="color: red;">&#8216;.txt&#8217;</span> </span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;">        </span><span style="color: blue;">from</span> #fixeddrives<span style="mso-spacerun: yes;">  </span></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;">       </span><span style="color: blue;">where</span> FreeSpace <span style="color: gray;">=</span> <span style="color: gray;">(</span><span style="color: blue;">select</span> <span style="color: fuchsia;">max</span><span style="color: gray;">(</span>FreeSpace<span style="color: gray;">)</span> <span style="color: blue;">from</span> #fixeddrives <span style="color: gray;">)</span> </span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;">       </span></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;">      </span><span style="color: green;">&#8211; Check for a pattern of &#8216;\\*\&#8217; or &#8216;?:\&#8217;. </span></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;">      </span><span style="color: green;">&#8211; If found assume the query is a file path. </span></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;">      </span><span style="color: blue;">If</span> <span style="color: gray;">Left(</span>@vcQuery<span style="color: gray;">,</span> 35<span style="color: gray;">)</span> <span style="color: gray;">like</span> <span style="color: red;">&#8216;\\%\%&#8217;</span> <span style="color: gray;">or</span> <span style="color: gray;">Left(</span>@vcQuery<span style="color: gray;">,</span> 5<span style="color: gray;">)</span> <span style="color: gray;">like</span> <span style="color: red;">&#8216;_:\%&#8217;</span> </span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;">         </span><span style="color: blue;">Begin</span> </span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;">            </span><span style="color: blue;">Select</span> @vcCmd <span style="color: gray;">=</span> <span style="color: red;">&#8216;osql /S&#8217;</span> <span style="color: gray;">+</span> @vcServerName <span style="color: gray;">+</span> <span style="color: red;">&#8216; /E /i&#8217;</span> <span style="color: gray;">+</span><span style="mso-spacerun: yes;">  </span></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;">                            </span><span style="color: fuchsia;">convert</span><span style="color: gray;">(</span><span style="color: blue;">varchar</span><span style="color: gray;">(</span>1024<span style="color: gray;">),</span>@vcQuery<span style="color: gray;">)</span> <span style="color: gray;">+</span> </span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;">                            </span><span style="color: red;">&#8216; /o&#8217;</span> <span style="color: gray;">+</span> @vcQueryOutPath <span style="color: gray;">+</span> <span style="color: red;">&#8216; -n -w5000 &#8216;</span> </span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;">         </span><span style="color: blue;">End</span> </span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;">      </span><span style="color: blue;">Else</span> </span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;">         </span><span style="color: blue;">Begin</span> </span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;">            </span><span style="color: blue;">Select</span> @vcCmd <span style="color: gray;">=</span> <span style="color: red;">&#8216;osql /S&#8217;</span> <span style="color: gray;">+</span> @vcServerName <span style="color: gray;">+</span> <span style="color: red;">&#8216; /E /Q&#8221;&#8216;</span> <span style="color: gray;">+</span> @vcQuery <span style="color: gray;">+</span> </span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;">                            </span><span style="color: red;">&#8216;&#8221; /o&#8217;</span> <span style="color: gray;">+</span> @vcQueryOutPath <span style="color: gray;">+</span> <span style="color: red;">&#8216; -n -w5000 &#8216;</span> </span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;">         </span><span style="color: blue;">End</span> </span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;">      </span><span style="color: green;">&#8211; Execute the query </span></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;">      </span><span style="color: blue;">Exec</span> master<span style="color: gray;">.</span>dbo<span style="color: gray;">.</span><span style="color: maroon;">xp_cmdshell</span> @vcCmd<span style="color: gray;">,</span> no_output </span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;">      </span><span style="color: green;">&#8211; Add the query results as an attachment if the file was successfully created. </span></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;">      </span><span style="color: green;">&#8211; Check to see if the file exists. Use xp_fileexist to determine this. </span></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;">      </span><span style="color: green;">&#8211; If a temp table exists with the following name drop it. </span></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;">      </span><span style="color: blue;">If</span> <span style="color: gray;">(</span><span style="color: blue;">Select</span> <span style="color: fuchsia;">object_id</span><span style="color: gray;">(</span><span style="color: red;">&#8216;tempdb.dbo.#fileexists&#8217;</span><span style="color: gray;">))</span> <span style="color: gray;">&gt;</span> 0 </span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;">         </span><span style="color: blue;">Exec</span> <span style="color: gray;">(</span><span style="color: red;">&#8216;Drop table #fileexists&#8217;</span><span style="color: gray;">)</span> </span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;">       </span></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;">      </span><span style="color: green;">&#8211; Create a temp table to work with xp_fileexist. </span></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;">      </span><span style="color: blue;">Create</span> <span style="color: blue;">table</span> #fileexists<span style="color: gray;">(</span> </span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;">             </span>FileExists <span style="color: blue;">tinyint</span> <span style="color: gray;">null,</span> </span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;">             </span>FileIsDirectory<span style="mso-spacerun: yes;">  </span><span style="color: blue;">tinyint</span> <span style="color: gray;">null,</span> </span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;">             </span>ParentDirectoryExists<span style="mso-spacerun: yes;">  </span><span style="color: blue;">tinyint</span> <span style="color: gray;">null)</span> </span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;">  </span><span style="color: green;">&#8211; Execute xp_fileexist </span></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;">      </span><span style="color: blue;">Insert</span> <span style="color: blue;">into</span> #fileexists <span style="color: blue;">exec</span> master<span style="color: gray;">.</span>dbo<span style="color: gray;">.</span>xp_fileexist @vcQueryOutPath </span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;">      </span><span style="color: green;">&#8211; Now see if we need to add the file as an attachment </span></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;">      </span><span style="color: blue;">If</span> <span style="color: gray;">(</span><span style="color: blue;">select</span> FileExists <span style="color: blue;">from</span> #fileexists<span style="color: gray;">)</span> <span style="color: gray;">=</span> 1 </span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;">         </span><span style="color: blue;">Begin</span> </span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;">            </span><span style="color: green;">&#8211; Set a variable for later use to delete the file. </span></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;">            </span><span style="color: blue;">Select</span> @iFileExists <span style="color: gray;">=</span> 1 </span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;">            </span><span style="color: green;">&#8211; Add the file path to the attachment variable. </span></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;">            </span><span style="color: blue;">If</span> @vcAttachments <span style="color: gray;">is</span> <span style="color: gray;">null</span> </span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;">               </span><span style="color: blue;">Select</span> @vcAttachments <span style="color: gray;">=</span> @vcQueryOutPath </span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;">            </span><span style="color: blue;">Else</span> </span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;">               </span><span style="color: blue;">Select</span> @vcAttachments <span style="color: gray;">=</span> @vcAttachments <span style="color: gray;">+</span> <span style="color: red;">&#8216;; &#8216;</span> <span style="color: gray;">+</span> @vcQueryOutPath </span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;">         </span><span style="color: blue;">End</span> </span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;">   </span><span style="color: blue;">End</span> </span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; color: green; font-family: &quot;Courier New&quot;; mso-no-proof: yes;">&#8211; Check for multiple attachments separated by a semi-colon &#8216;;&#8217;. </span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; color: blue; font-family: &quot;Courier New&quot;; mso-no-proof: yes;">If</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"> @vcAttachments <span style="color: gray;">is</span> <span style="color: gray;">not</span> <span style="color: gray;">null</span> </span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;">   </span><span style="color: blue;">Begin</span> </span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;">      </span><span style="color: blue;">If</span> <span style="color: gray;">right(</span>@vcAttachments<span style="color: gray;">,</span>1<span style="color: gray;">)</span> <span style="color: gray;">&lt;&gt;</span> <span style="color: red;">&#8216;;&#8217;</span> </span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;">         </span><span style="color: blue;">Select</span> @vcAttachments <span style="color: gray;">=</span> @vcAttachments <span style="color: gray;">+</span> <span style="color: red;">&#8216;; &#8216;</span> </span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;">      </span><span style="color: blue;">Select</span> @iPos <span style="color: gray;">=</span> <span style="color: fuchsia;">CharIndex</span><span style="color: gray;">(</span><span style="color: red;">&#8216;;&#8217;</span><span style="color: gray;">,</span> @vcAttachments<span style="color: gray;">,</span> 1<span style="color: gray;">)</span> </span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;">      </span><span style="color: blue;">While</span> @iPos <span style="color: gray;">&gt;</span> 0 </span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;">         </span><span style="color: blue;">Begin</span><span style="mso-spacerun: yes;">  </span></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;">            </span><span style="color: blue;">Select</span> @vcAttachment <span style="color: gray;">=</span> <span style="color: fuchsia;">ltrim</span><span style="color: gray;">(</span><span style="color: fuchsia;">rtrim</span><span style="color: gray;">(</span><span style="color: fuchsia;">substring</span><span style="color: gray;">(</span>@vcAttachments<span style="color: gray;">,</span> 1<span style="color: gray;">,</span> @iPos <span style="color: gray;">-</span>1<span style="color: gray;">)))</span> </span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;">            </span><span style="color: blue;">Select</span> @vcAttachments <span style="color: gray;">=</span> <span style="color: fuchsia;">substring</span><span style="color: gray;">(</span>@vcAttachments<span style="color: gray;">,</span> @iPos <span style="color: gray;">+</span> 1<span style="color: gray;">,</span> <span style="color: fuchsia;">Len</span><span style="color: gray;">(</span>@vcAttachments<span style="color: gray;">)-</span>@iPos<span style="color: gray;">)</span> </span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;">            </span><span style="color: blue;">EXEC</span> @iHr <span style="color: gray;">=</span> sp_OAMethod @iMessageObjId<span style="color: gray;">,</span> <span style="color: red;">&#8216;AddAttachment&#8217;</span><span style="color: gray;">,</span> @iRtn <span style="color: blue;">Out</span><span style="color: gray;">,</span> @vcAttachment </span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;">            </span><span style="color: blue;">IF</span> @iHr <span style="color: gray;">&lt;&gt;</span> 0<span style="mso-spacerun: yes;">  </span></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;">               </span><span style="color: blue;">Begin</span> </span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;">                  </span><span style="color: blue;">EXEC</span> sp_OAGetErrorInfo @iMessageObjId<span style="color: gray;">,</span> @vcErrSource <span style="color: blue;">Out</span><span style="color: gray;">,</span> @vcErrDescription <span style="color: blue;">Out</span><span style="mso-spacerun: yes;">  </span></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;">                  </span><span style="color: blue;">Select</span> @vcBody <span style="color: gray;">=</span> @vcBody <span style="color: gray;">+</span> <span style="color: blue;">char</span><span style="color: gray;">(</span>13<span style="color: gray;">)</span> <span style="color: gray;">+</span> <span style="color: blue;">char</span><span style="color: gray;">(</span>10<span style="color: gray;">)</span> <span style="color: gray;">+</span> <span style="color: blue;">char</span><span style="color: gray;">(</span>13<span style="color: gray;">)</span> <span style="color: gray;">+</span> <span style="color: blue;">char</span><span style="color: gray;">(</span>10<span style="color: gray;">)</span> <span style="color: gray;">+</span><span style="mso-spacerun: yes;">  </span></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;">                                   </span><span style="color: blue;">char</span><span style="color: gray;">(</span>13<span style="color: gray;">)</span> <span style="color: gray;">+</span> <span style="color: blue;">char</span><span style="color: gray;">(</span>10<span style="color: gray;">)</span> <span style="color: gray;">+</span> <span style="color: red;">&#8216;Error adding attachment: &#8216;</span> <span style="color: gray;">+</span> </span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;">                                   </span><span style="color: blue;">char</span><span style="color: gray;">(</span>13<span style="color: gray;">)</span> <span style="color: gray;">+</span> <span style="color: blue;">char</span><span style="color: gray;">(</span>10<span style="color: gray;">)</span> <span style="color: gray;">+</span> @vcErrSource <span style="color: gray;">+</span> <span style="color: blue;">char</span><span style="color: gray;">(</span>13<span style="color: gray;">)</span> <span style="color: gray;">+</span> <span style="color: blue;">char</span><span style="color: gray;">(</span>10<span style="color: gray;">)</span> <span style="color: gray;">+</span><span style="mso-spacerun: yes;">  </span></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;">                                   </span>@vcAttachment </span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;">               </span><span style="color: blue;">End</span> </span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;">            </span><span style="color: blue;">Select</span> @iPos <span style="color: gray;">=</span> <span style="color: fuchsia;">CharIndex</span><span style="color: gray;">(</span><span style="color: red;">&#8216;;&#8217;</span><span style="color: gray;">,</span> @vcAttachments<span style="color: gray;">,</span> 1<span style="color: gray;">)</span> </span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;">         </span><span style="color: blue;">End</span> </span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;">   </span><span style="color: blue;">End</span> </span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; color: green; font-family: &quot;Courier New&quot;; mso-no-proof: yes;">&#8211; TextBody </span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; color: blue; font-family: &quot;Courier New&quot;; mso-no-proof: yes;">EXEC</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"> @iHr <span style="color: gray;">=</span> sp_OASetProperty @iMessageObjId<span style="color: gray;">,</span> <span style="color: red;">&#8216;TextBody&#8217;</span><span style="color: gray;">,</span> @vcBody<span style="mso-spacerun: yes;">  </span></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; color: blue; font-family: &quot;Courier New&quot;; mso-no-proof: yes;">IF</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"> @iHr <span style="color: gray;">&lt;&gt;</span> 0<span style="mso-spacerun: yes;">  </span></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;">   </span><span style="color: blue;">Begin</span><span style="mso-spacerun: yes;">  </span></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;">      </span><span style="color: blue;">Set</span> @vcErrMssg <span style="color: gray;">=</span> <span style="color: red;">&#8216;Error setting Message parameter &#8220;TextBody&#8221;.&#8217;</span> </span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;">      </span><span style="color: blue;">Goto</span> ErrMssg<span style="mso-spacerun: yes;">  </span></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;">   </span><span style="color: blue;">End</span> </span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; color: green; font-family: &quot;Courier New&quot;; mso-no-proof: yes;">&#8211; Other Message parameters for reference </span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; color: green; font-family: &quot;Courier New&quot;; mso-no-proof: yes;">&#8211;EXEC @iHr = sp_OASetProperty @iMessageObjId, &#8216;MimeFormatted&#8217;, False </span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; color: green; font-family: &quot;Courier New&quot;; mso-no-proof: yes;">&#8211;EXEC @iHr = sp_OASetProperty @iMessageObjId, &#8216;AutoGenerateTextBody&#8217;, False </span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; color: green; font-family: &quot;Courier New&quot;; mso-no-proof: yes;">&#8211;EXEC @iHr = sp_OASetProperty @iMessageObjId, &#8216;MDNRequested&#8217;, True </span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; color: green; font-family: &quot;Courier New&quot;; mso-no-proof: yes;">&#8211; Set SMTP Message configuration property values. </span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; color: green; font-family: &quot;Courier New&quot;; mso-no-proof: yes;">&#8211; Network SMTP Server location </span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; color: blue; font-family: &quot;Courier New&quot;; mso-no-proof: yes;">EXEC</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"> @iHr <span style="color: gray;">=</span> sp_OASetProperty @iMessageObjId<span style="color: gray;">,</span><span style="mso-spacerun: yes;">  </span></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; color: red; font-family: &quot;Courier New&quot;; mso-no-proof: yes;">&#8216;Configuration.Fields(&#8220;http://schemas.microsoft.com/cdo/configuration/smtpserver&#8221;).Value&#8217;</span><span style="font-size: 10pt; color: gray; font-family: &quot;Courier New&quot;; mso-no-proof: yes;">,</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;">  </span></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;">@vcSMTPServer </span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; color: blue; font-family: &quot;Courier New&quot;; mso-no-proof: yes;">IF</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"> @iHr <span style="color: gray;">&lt;&gt;</span> 0<span style="mso-spacerun: yes;">  </span></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span><span style="mso-spacerun: yes;">  </span><span style="color: blue;">Begin</span><span style="mso-spacerun: yes;">  </span></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;">      </span><span style="color: blue;">Set</span> @vcErrMssg <span style="color: gray;">=</span> <span style="color: red;">&#8216;Error setting Message configuraton field &#8220;smtpserver&#8221;.&#8217;</span> </span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;">      </span><span style="color: blue;">Goto</span> ErrMssg<span style="mso-spacerun: yes;">  </span></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;">   </span><span style="color: blue;">End</span> </span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; color: green; font-family: &quot;Courier New&quot;; mso-no-proof: yes;">&#8211; Sendusing </span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; color: blue; font-family: &quot;Courier New&quot;; mso-no-proof: yes;">EXEC</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"> @iHr <span style="color: gray;">=</span> sp_OASetProperty @iMessageObjId<span style="color: gray;">,</span><span style="mso-spacerun: yes;">  </span></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; color: red; font-family: &quot;Courier New&quot;; mso-no-proof: yes;">&#8216;Configuration.Fields(&#8220;http://schemas.microsoft.com/cdo/configuration/sendusing&#8221;).Value&#8217;</span><span style="font-size: 10pt; color: gray; font-family: &quot;Courier New&quot;; mso-no-proof: yes;">,</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"> </span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;">@cSendUsing </span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; color: blue; font-family: &quot;Courier New&quot;; mso-no-proof: yes;">IF</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"> @iHr <span style="color: gray;">&lt;&gt;</span> 0<span style="mso-spacerun: yes;">  </span></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;">   </span><span style="color: blue;">Begin</span><span style="mso-spacerun: yes;">  </span></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;">      </span><span style="color: blue;">Set</span> @vcErrMssg <span style="color: gray;">=</span> <span style="color: red;">&#8216;Error setting Message configuraton field &#8220;sendusing&#8221;.&#8217;</span> </span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;">      </span><span style="color: blue;">Goto</span> ErrMssg<span style="mso-spacerun: yes;">  </span></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;">   </span><span style="color: blue;">End</span> </span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; color: green; font-family: &quot;Courier New&quot;; mso-no-proof: yes;">&#8211; SMTPConnectionTimeout </span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; color: blue; font-family: &quot;Courier New&quot;; mso-no-proof: yes;">EXEC</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"> @iHr <span style="color: gray;">=</span> sp_OASetProperty @iMessageObjId<span style="color: gray;">,</span><span style="mso-spacerun: yes;">  </span></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; color: red; font-family: &quot;Courier New&quot;; mso-no-proof: yes;">&#8216;Configuration.Fields(&#8220;http://schemas.microsoft.com/cdo/configuration/SMTPConnectionTimeout&#8221;).Value&#8217;</span><span style="font-size: 10pt; color: gray; font-family: &quot;Courier New&quot;; mso-no-proof: yes;">,</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"> </span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;">@vcTimeout </span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; color: blue; font-family: &quot;Courier New&quot;; mso-no-proof: yes;">IF</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"> @iHr <span style="color: gray;">&lt;&gt;</span> 0<span style="mso-spacerun: yes;">  </span></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;">   </span><span style="color: blue;">Begin</span><span style="mso-spacerun: yes;">  </span></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;">      </span><span style="color: blue;">Set</span> @vcErrMssg <span style="color: gray;">=</span> <span style="color: red;">&#8216;Error setting Message configuraton field &#8220;SMTPConnectionTimeout&#8221;.&#8217;</span> </span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;">      </span><span style="color: blue;">Goto</span> ErrMssg<span style="mso-spacerun: yes;">  </span></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;">   </span><span style="color: blue;">End</span> </span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; color: green; font-family: &quot;Courier New&quot;; mso-no-proof: yes;">&#8211; SMTPServerPort </span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; color: blue; font-family: &quot;Courier New&quot;; mso-no-proof: yes;">EXEC</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"> @iHr <span style="color: gray;">=</span> sp_OASetProperty @iMessageObjId<span style="color: gray;">,</span><span style="mso-spacerun: yes;">  </span></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; color: red; font-family: &quot;Courier New&quot;; mso-no-proof: yes;">&#8216;Configuration.Fields(&#8220;http://schemas.microsoft.com/cdo/configuration/SMTPServerPort&#8221;).Value&#8217;</span><span style="font-size: 10pt; color: gray; font-family: &quot;Courier New&quot;; mso-no-proof: yes;">,</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"> </span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;">@vcPort </span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; color: blue; font-family: &quot;Courier New&quot;; mso-no-proof: yes;">IF</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"> @iHr <span style="color: gray;">&lt;&gt;</span> 0<span style="mso-spacerun: yes;">  </span></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;">   </span><span style="color: blue;">Begin</span><span style="mso-spacerun: yes;">  </span></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;">      </span><span style="color: blue;">Set</span> @vcErrMssg <span style="color: gray;">=</span> <span style="color: red;">&#8216;Error setting Message configuraton field &#8220;SMTPServerPort&#8221;.&#8217;</span> </span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;">      </span><span style="color: blue;">Goto</span> ErrMssg<span style="mso-spacerun: yes;">  </span></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;">   </span><span style="color: blue;">End</span> </span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; color: green; font-family: &quot;Courier New&quot;; mso-no-proof: yes;">&#8211; SMTPAuthenticate </span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; color: blue; font-family: &quot;Courier New&quot;; mso-no-proof: yes;">EXEC</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"> @iHr <span style="color: gray;">=</span> sp_OASetProperty @iMessageObjId<span style="color: gray;">,</span><span style="mso-spacerun: yes;">  </span></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; color: red; font-family: &quot;Courier New&quot;; mso-no-proof: yes;">&#8216;Configuration.Fields(&#8220;http://schemas.microsoft.com/cdo/configuration/SMTPAuthenticate&#8221;).Value&#8217;</span><span style="font-size: 10pt; color: gray; font-family: &quot;Courier New&quot;; mso-no-proof: yes;">,</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"> </span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;">@cAuthenticate </span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; color: blue; font-family: &quot;Courier New&quot;; mso-no-proof: yes;">IF</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"> @iHr <span style="color: gray;">&lt;&gt;</span> 0<span style="mso-spacerun: yes;">  </span></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;">   </span><span style="color: blue;">Begin</span><span style="mso-spacerun: yes;">  </span></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;">      </span><span style="color: blue;">Set</span> @vcErrMssg <span style="color: gray;">=</span> <span style="color: red;">&#8216;Error setting Message configuraton field &#8220;SMTPAuthenticate&#8221;.&#8217;</span> </span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;">      </span><span style="color: blue;">Goto</span> ErrMssg<span style="mso-spacerun: yes;">  </span></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;">   </span><span style="color: blue;">End</span> </span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; color: green; font-family: &quot;Courier New&quot;; mso-no-proof: yes;">&#8211; Other Message Configuration fields for reference </span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; color: green; font-family: &quot;Courier New&quot;; mso-no-proof: yes;">&#8211;EXEC @iHr = sp_OASetProperty @iMessageObjId,<span style="mso-spacerun: yes;">  </span></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; color: green; font-family: &quot;Courier New&quot;; mso-no-proof: yes;">&#8211;&#8217;Configuration.Fields(&#8220;http://schemas.microsoft.com/cdo/configuration/SMTPUseSSL&#8221;).Value&#8217;,True </span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; color: green; font-family: &quot;Courier New&quot;; mso-no-proof: yes;">&#8211;EXEC @iHr = sp_OASetProperty @iMessageObjId,<span style="mso-spacerun: yes;">  </span></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; color: green; font-family: &quot;Courier New&quot;; mso-no-proof: yes;">&#8211;&#8217;Configuration.Fields(&#8220;http://schemas.microsoft.com/cdo/configuration/LanguageCode&#8221;).Value&#8217;,'en&#8217; </span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; color: green; font-family: &quot;Courier New&quot;; mso-no-proof: yes;">&#8211;EXEC @iHr = sp_OASetProperty @iMessageObjId,<span style="mso-spacerun: yes;">  </span></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; color: green; font-family: &quot;Courier New&quot;; mso-no-proof: yes;">&#8211;&#8217;Configuration.Fields(&#8220;http://schemas.microsoft.com/cdo/configuration/SendEmailAddress&#8221;).Value&#8217;, &#8216;Test User&#8217; </span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; color: green; font-family: &quot;Courier New&quot;; mso-no-proof: yes;">&#8211;EXEC @iHr = sp_OASetProperty @iMessageObjId,<span style="mso-spacerun: yes;">  </span></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; color: green; font-family: &quot;Courier New&quot;; mso-no-proof: yes;">&#8211;&#8217;Configuration.Fields(&#8220;http://schemas.microsoft.com/cdo/configuration/SendUserName&#8221;).Value&#8217;,null </span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; color: green; font-family: &quot;Courier New&quot;; mso-no-proof: yes;">&#8211;EXEC @iHr = sp_OASetProperty @iMessageObjId,<span style="mso-spacerun: yes;">  </span></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; color: green; font-family: &quot;Courier New&quot;; mso-no-proof: yes;">&#8211;&#8217;Configuration.Fields(&#8220;http://schemas.microsoft.com/cdo/configuration/SendPassword&#8221;).Value&#8217;,null </span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; color: green; font-family: &quot;Courier New&quot;; mso-no-proof: yes;">&#8211; Update the Message object fields and configuration fields. </span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; color: blue; font-family: &quot;Courier New&quot;; mso-no-proof: yes;">EXEC</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"> @iHr <span style="color: gray;">=</span> sp_OAMethod @iMessageObjId<span style="color: gray;">,</span> <span style="color: red;">&#8216;Configuration.Fields.Update&#8217;</span> </span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; color: blue; font-family: &quot;Courier New&quot;; mso-no-proof: yes;">IF</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"> @iHr <span style="color: gray;">&lt;&gt;</span> 0<span style="mso-spacerun: yes;">  </span></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;">   </span><span style="color: blue;">Begin</span><span style="mso-spacerun: yes;">  </span></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;">      </span><span style="color: blue;">Set</span> @vcErrMssg <span style="color: gray;">=</span> <span style="color: red;">&#8216;Error updating Message configuration fields.&#8217;</span> </span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;">      </span><span style="color: blue;">Goto</span> ErrMssg<span style="mso-spacerun: yes;">  </span></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;">   </span><span style="color: blue;">End</span> </span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; color: blue; font-family: &quot;Courier New&quot;; mso-no-proof: yes;">EXEC</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"> @iHr <span style="color: gray;">=</span> sp_OAMethod @iMessageObjId<span style="color: gray;">,</span> <span style="color: red;">&#8216;Fields.Update&#8217;</span> </span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; color: blue; font-family: &quot;Courier New&quot;; mso-no-proof: yes;">IF</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"> @iHr <span style="color: gray;">&lt;&gt;</span> 0<span style="mso-spacerun: yes;">  </span></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;">   </span><span style="color: blue;">Begin</span><span style="mso-spacerun: yes;">  </span></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;">      </span><span style="color: blue;">Set</span> @vcErrMssg <span style="color: gray;">=</span> <span style="color: red;">&#8216;Error updating Message parameters.&#8217;</span> </span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;">      </span><span style="color: blue;">Goto</span> ErrMssg<span style="mso-spacerun: yes;">  </span></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;">   </span><span style="color: blue;">End</span> </span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; color: green; font-family: &quot;Courier New&quot;; mso-no-proof: yes;">&#8211; Send the message. </span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; color: blue; font-family: &quot;Courier New&quot;; mso-no-proof: yes;">EXEC</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"> @iHr <span style="color: gray;">=</span> sp_OAMethod @iMessageObjId<span style="color: gray;">,</span> <span style="color: red;">&#8216;Send&#8217;</span> </span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; color: blue; font-family: &quot;Courier New&quot;; mso-no-proof: yes;">IF</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"> @iHr <span style="color: gray;">&lt;&gt;</span> 0<span style="mso-spacerun: yes;">  </span></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;">   </span><span style="color: blue;">Begin</span><span style="mso-spacerun: yes;">  </span></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;">      </span><span style="color: blue;">Set</span> @vcErrMssg <span style="color: gray;">=</span> <span style="color: red;">&#8216;Error Sending e-mail.&#8217;</span> </span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;">      </span><span style="color: blue;">Goto</span> ErrMssg<span style="mso-spacerun: yes;">  </span></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;">   </span><span style="color: blue;">End</span> </span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; color: blue; font-family: &quot;Courier New&quot;; mso-no-proof: yes;">Else</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;">  </span></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;">   </span><span style="color: blue;">Print</span> <span style="color: red;">&#8216;Mail sent.&#8217;</span> </span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;">Cleanup<span style="color: gray;">:</span> </span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;">   </span><span style="color: green;">&#8211; Destroy the object and return. </span></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;">   </span><span style="color: blue;">EXEC</span> @iHr <span style="color: gray;">=</span> sp_OADestroy @iMessageObjId </span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;">   </span><span style="color: green;">&#8211;EXEC @iHr = sp_OAStop </span></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;">   </span><span style="color: green;">&#8211; Delete the query output file if one exists. </span></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;">   </span><span style="color: blue;">If</span> @iFileExists <span style="color: gray;">=</span> 1 </span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;">      </span><span style="color: blue;">Begin</span> </span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;">         </span><span style="color: blue;">Select</span> @vcCmd <span style="color: gray;">=</span> <span style="color: red;">&#8216;del &#8216;</span> <span style="color: gray;">+</span> @vcQueryOutPath </span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;">         </span><span style="color: blue;">Exec</span> master<span style="color: gray;">.</span>dbo<span style="color: gray;">.</span><span style="color: maroon;">xp_cmdshell</span> @vcCmd<span style="color: gray;">,</span> no_output </span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;">      </span><span style="color: blue;">End</span> </span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;">   </span><span style="color: blue;">Return</span> </span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;">ErrMssg<span style="color: gray;">:</span> </span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;">   </span><span style="color: blue;">Begin</span> </span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;">      </span><span style="color: blue;">Print</span> @vcErrMssg </span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;">      </span><span style="color: blue;">If</span> @iHr <span style="color: gray;">&lt;&gt;</span> 0<span style="mso-spacerun: yes;">  </span></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;">         </span><span style="color: blue;">Begin</span> </span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;">            </span><span style="color: blue;">EXEC</span> sp_OAGetErrorInfo @iMessageObjId<span style="color: gray;">,</span> @vcErrSource <span style="color: blue;">Out</span><span style="color: gray;">,</span> @vcErrDescription <span style="color: blue;">Out</span><span style="mso-spacerun: yes;">  </span></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;">            </span><span style="color: blue;">Print</span> @vcErrSource </span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;">            </span><span style="color: blue;">Print</span> @vcErrDescription </span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;">         </span><span style="color: blue;">End</span> </span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;">      </span><span style="color: green;">&#8211; Determine whether to exist or go to Cleanup. </span></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;">      </span><span style="color: blue;">If</span> @vcErrMssg <span style="color: gray;">=</span> <span style="color: red;">&#8216;Error creating object CDO.Message.&#8217;</span> </span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;">         </span><span style="color: blue;">Return</span> </span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;">      </span><span style="color: blue;">Else</span> </span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;">         </span><span style="color: blue;">Goto</span> Cleanup </span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;">   </span><span style="color: blue;">End</span> </span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;">GO</span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"> </span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt;"><span style="font-size: small; font-family: Times New Roman;"> </span></p>
]]></content:encoded>
			<wfw:commentRss>http://rickcaminiti.com/tips/sending-mail-mssql/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Delete TOP n Records in T-SQL</title>
		<link>http://rickcaminiti.com/tips/delete-top-records-tsql/</link>
		<comments>http://rickcaminiti.com/tips/delete-top-records-tsql/#comments</comments>
		<pubDate>Wed, 13 May 2009 18:11:02 +0000</pubDate>
		<dc:creator>NothingMan</dc:creator>
				<category><![CDATA[BI]]></category>
		<category><![CDATA[Code]]></category>
		<category><![CDATA[Tips]]></category>
		<category><![CDATA[mssql]]></category>
		<category><![CDATA[sql]]></category>

		<guid isPermaLink="false">http://rickcaminiti.com/?p=320</guid>
		<description>If you&amp;#8217;re trying to delete the first n records in a table, here&amp;#8217;s how to do it in SQL 2005:   use master select *   into #temptable   from information_schema.tables (12 row(s) affected)   select *   from #temptable       TABLE_CATALOG TABLE_SCHEMA TABLE_NAME TABLE_TYPE master dbo spt_fallback_db BASE TABLE master dbo spt_fallback_dev BASE TABLE master [...]</description>
			<content:encoded><![CDATA[<p class="MsoNormal" style="margin: 0in 0in 0pt;"><span style="font-size: small; font-family: Times New Roman;">If you&#8217;re trying to delete the first n records in a table, here&#8217;s how to do it in SQL 2005:<span id="more-320"></span></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt;"><span style="font-size: small; font-family: Times New Roman;"> </span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; color: blue; font-family: &quot;Courier New&quot;; mso-no-proof: yes;">use</span><span style="font-size: 10pt; color: black; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"> </span><span style="font-size: 10pt; color: blue; font-family: &quot;Courier New&quot;; mso-no-proof: yes;">master</span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; color: blue; font-family: &quot;Courier New&quot;; mso-no-proof: yes;">select</span><span style="font-size: 10pt; color: black; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"> </span><span style="font-size: 10pt; color: gray; font-family: &quot;Courier New&quot;; mso-no-proof: yes;">*</span><span style="font-size: 10pt; color: black; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"> </span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; color: black; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span><span style="mso-spacerun: yes;"> </span></span><span style="font-size: 10pt; color: blue; font-family: &quot;Courier New&quot;; mso-no-proof: yes;">into</span><span style="font-size: 10pt; color: black; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"> #temptable </span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; color: black; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span><span style="mso-spacerun: yes;"> </span></span><span style="font-size: 10pt; color: blue; font-family: &quot;Courier New&quot;; mso-no-proof: yes;">from</span><span style="font-size: 10pt; color: black; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"> </span><span style="font-size: 10pt; color: green; font-family: &quot;Courier New&quot;; mso-no-proof: yes;">information_schema.tables<br />
</span><span style="font-size: 10pt; color: gray; font-family: &quot;Courier New&quot;; mso-no-proof: yes;">(12</span><span style="font-size: 10pt; color: black; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"> row</span><span style="font-size: 10pt; color: gray; font-family: &quot;Courier New&quot;; mso-no-proof: yes;">(</span><span style="font-size: 10pt; color: black; font-family: &quot;Courier New&quot;; mso-no-proof: yes;">s</span><span style="font-size: 10pt; color: gray; font-family: &quot;Courier New&quot;; mso-no-proof: yes;">)</span><span style="font-size: 10pt; color: black; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"> affected</span><span style="font-size: 10pt; color: gray; font-family: &quot;Courier New&quot;; mso-no-proof: yes;">)</span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-margin-top-alt: auto; mso-margin-bottom-alt: auto;"><span style="font-size: 10pt; color: green; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"> </span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; color: blue; font-family: &quot;Courier New&quot;; mso-no-proof: yes;">select</span><span style="font-size: 10pt; color: black; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"> </span><span style="font-size: 10pt; color: gray; font-family: &quot;Courier New&quot;; mso-no-proof: yes;">*</span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; color: black; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span><span style="mso-spacerun: yes;"> </span></span><span style="font-size: 10pt; color: blue; font-family: &quot;Courier New&quot;; mso-no-proof: yes;">from</span><span style="font-size: 10pt; color: black; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"> #temptable</span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"> </p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"> </p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-margin-top-alt: auto; mso-margin-bottom-alt: auto;"><span style="font-size: 10pt; color: green; font-family: Verdana;">  </span></p>
<table class="MsoNormalTable" style="width: 366pt; border-collapse: collapse; mso-padding-alt: 0in 0in 0in 0in;" border="0" cellspacing="0" cellpadding="0" width="488">
<tbody>
<tr style="height: 12.75pt; mso-yfti-irow: 0; mso-yfti-firstrow: yes;">
<td style="width: 91pt; height: 12.75pt; background-color: transparent; border: #ece9d8; padding: 0in;" width="121">
<p class="MsoNormal" style="margin: 6pt;"><strong><span style="font-size: 10pt; color: black; font-family: Arial; mso-bidi-font-size: 12.0pt;">TABLE_CATALOG</span></strong></p>
</td>
<td style="width: 84pt; height: 12.75pt; background-color: transparent; border: #ece9d8; padding: 0in;" width="112">
<p class="MsoNormal" style="margin: 6pt;"><strong><span style="font-size: 10pt; color: black; font-family: Arial; mso-bidi-font-size: 12.0pt;">TABLE_SCHEMA</span></strong></p>
</td>
<td style="width: 124pt; height: 12.75pt; background-color: transparent; border: #ece9d8; padding: 0in;" width="165">
<p class="MsoNormal" style="margin: 6pt;"><strong><span style="font-size: 10pt; color: black; font-family: Arial; mso-bidi-font-size: 12.0pt;">TABLE_NAME</span></strong></p>
</td>
<td style="width: 67pt; height: 12.75pt; background-color: transparent; border: #ece9d8; padding: 0in;" width="89">
<p class="MsoNormal" style="margin: 6pt;"><strong><span style="font-size: 10pt; color: black; font-family: Arial; mso-bidi-font-size: 12.0pt;">TABLE_TYPE</span></strong></p>
</td>
</tr>
<tr style="height: 12.75pt; mso-yfti-irow: 1;">
<td style="height: 12.75pt; background-color: transparent; border: #ece9d8; padding: 0in;">
<p class="MsoNormal" style="margin: 6pt;"><span style="font-size: 10pt; color: black; font-family: Arial;">master</span></p>
</td>
<td style="height: 12.75pt; background-color: transparent; border: #ece9d8; padding: 0in;">
<p class="MsoNormal" style="margin: 6pt;"><span style="font-size: 10pt; color: black; font-family: Arial;">dbo</span></p>
</td>
<td style="height: 12.75pt; background-color: transparent; border: #ece9d8; padding: 0in;">
<p class="MsoNormal" style="margin: 6pt;"><span style="font-size: 10pt; color: black; font-family: Arial;">spt_fallback_db</span></p>
</td>
<td style="height: 12.75pt; background-color: transparent; border: #ece9d8; padding: 0in;">
<p class="MsoNormal" style="margin: 6pt;"><span style="font-size: 10pt; color: black; font-family: Arial;">BASE TABLE</span></p>
</td>
</tr>
<tr style="height: 12.75pt; mso-yfti-irow: 2;">
<td style="height: 12.75pt; background-color: transparent; border: #ece9d8; padding: 0in;">
<p class="MsoNormal" style="margin: 6pt;"><span style="font-size: 10pt; color: black; font-family: Arial;">master</span></p>
</td>
<td style="height: 12.75pt; background-color: transparent; border: #ece9d8; padding: 0in;">
<p class="MsoNormal" style="margin: 6pt;"><span style="font-size: 10pt; color: black; font-family: Arial;">dbo</span></p>
</td>
<td style="height: 12.75pt; background-color: transparent; border: #ece9d8; padding: 0in;">
<p class="MsoNormal" style="margin: 6pt;"><span style="font-size: 10pt; color: black; font-family: Arial;">spt_fallback_dev</span></p>
</td>
<td style="height: 12.75pt; background-color: transparent; border: #ece9d8; padding: 0in;">
<p class="MsoNormal" style="margin: 6pt;"><span style="font-size: 10pt; color: black; font-family: Arial;">BASE TABLE</span></p>
</td>
</tr>
<tr style="height: 12.75pt; mso-yfti-irow: 3;">
<td style="height: 12.75pt; background-color: transparent; border: #ece9d8; padding: 0in;">
<p class="MsoNormal" style="margin: 6pt;"><span style="font-size: 10pt; color: black; font-family: Arial;">master</span></p>
</td>
<td style="height: 12.75pt; background-color: transparent; border: #ece9d8; padding: 0in;">
<p class="MsoNormal" style="margin: 6pt;"><span style="font-size: 10pt; color: black; font-family: Arial;">dbo</span></p>
</td>
<td style="height: 12.75pt; background-color: transparent; border: #ece9d8; padding: 0in;">
<p class="MsoNormal" style="margin: 6pt;"><span style="font-size: 10pt; color: black; font-family: Arial;">spt_fallback_usg</span></p>
</td>
<td style="height: 12.75pt; background-color: transparent; border: #ece9d8; padding: 0in;">
<p class="MsoNormal" style="margin: 6pt;"><span style="font-size: 10pt; color: black; font-family: Arial;">BASE TABLE</span></p>
</td>
</tr>
<tr style="height: 12.75pt; mso-yfti-irow: 4;">
<td style="height: 12.75pt; background-color: transparent; border: #ece9d8; padding: 0in;">
<p class="MsoNormal" style="margin: 6pt;"><span style="font-size: 10pt; color: black; font-family: Arial;">master</span></p>
</td>
<td style="height: 12.75pt; background-color: transparent; border: #ece9d8; padding: 0in;">
<p class="MsoNormal" style="margin: 6pt;"><span style="font-size: 10pt; color: black; font-family: Arial;">dbo</span></p>
</td>
<td style="height: 12.75pt; background-color: transparent; border: #ece9d8; padding: 0in;">
<p class="MsoNormal" style="margin: 6pt;"><span style="font-size: 10pt; color: black; font-family: Arial;">lgnstats</span></p>
</td>
<td style="height: 12.75pt; background-color: transparent; border: #ece9d8; padding: 0in;">
<p class="MsoNormal" style="margin: 6pt;"><span style="font-size: 10pt; color: black; font-family: Arial;">BASE TABLE</span></p>
</td>
</tr>
<tr style="height: 12.75pt; mso-yfti-irow: 5;">
<td style="height: 12.75pt; background-color: transparent; border: #ece9d8; padding: 0in;">
<p class="MsoNormal" style="margin: 6pt;"><span style="font-size: 10pt; color: black; font-family: Arial;">master</span></p>
</td>
<td style="height: 12.75pt; background-color: transparent; border: #ece9d8; padding: 0in;">
<p class="MsoNormal" style="margin: 6pt;"><span style="font-size: 10pt; color: black; font-family: Arial;">dbo</span></p>
</td>
<td style="height: 12.75pt; background-color: transparent; border: #ece9d8; padding: 0in;">
<p class="MsoNormal" style="margin: 6pt;"><span style="font-size: 10pt; color: black; font-family: Arial;">pc_PluEventXref</span></p>
</td>
<td style="height: 12.75pt; background-color: transparent; border: #ece9d8; padding: 0in;">
<p class="MsoNormal" style="margin: 6pt;"><span style="font-size: 10pt; color: black; font-family: Arial;">BASE TABLE</span></p>
</td>
</tr>
<tr style="height: 12.75pt; mso-yfti-irow: 6;">
<td style="height: 12.75pt; background-color: transparent; border: #ece9d8; padding: 0in;">
<p class="MsoNormal" style="margin: 6pt;"><span style="font-size: 10pt; color: black; font-family: Arial;">master</span></p>
</td>
<td style="height: 12.75pt; background-color: transparent; border: #ece9d8; padding: 0in;">
<p class="MsoNormal" style="margin: 6pt;"><span style="font-size: 10pt; color: black; font-family: Arial;">dbo</span></p>
</td>
<td style="height: 12.75pt; background-color: transparent; border: #ece9d8; padding: 0in;">
<p class="MsoNormal" style="margin: 6pt;"><span style="font-size: 10pt; color: black; font-family: Arial;">LogonAudit</span></p>
</td>
<td style="height: 12.75pt; background-color: transparent; border: #ece9d8; padding: 0in;">
<p class="MsoNormal" style="margin: 6pt;"><span style="font-size: 10pt; color: black; font-family: Arial;">BASE TABLE</span></p>
</td>
</tr>
<tr style="height: 12.75pt; mso-yfti-irow: 7;">
<td style="height: 12.75pt; background-color: transparent; border: #ece9d8; padding: 0in;">
<p class="MsoNormal" style="margin: 6pt;"><span style="font-size: 10pt; color: black; font-family: Arial;">master</span></p>
</td>
<td style="height: 12.75pt; background-color: transparent; border: #ece9d8; padding: 0in;">
<p class="MsoNormal" style="margin: 6pt;"><span style="font-size: 10pt; color: black; font-family: Arial;">dbo</span></p>
</td>
<td style="height: 12.75pt; background-color: transparent; border: #ece9d8; padding: 0in;">
<p class="MsoNormal" style="margin: 6pt;"><span style="font-size: 10pt; color: black; font-family: Arial;">DBAobjectCNT</span></p>
</td>
<td style="height: 12.75pt; background-color: transparent; border: #ece9d8; padding: 0in;">
<p class="MsoNormal" style="margin: 6pt;"><span style="font-size: 10pt; color: black; font-family: Arial;">BASE TABLE</span></p>
</td>
</tr>
<tr style="height: 12.75pt; mso-yfti-irow: 8;">
<td style="height: 12.75pt; background-color: transparent; border: #ece9d8; padding: 0in;">
<p class="MsoNormal" style="margin: 6pt;"><span style="font-size: 10pt; color: black; font-family: Arial;">master</span></p>
</td>
<td style="height: 12.75pt; background-color: transparent; border: #ece9d8; padding: 0in;">
<p class="MsoNormal" style="margin: 6pt;"><span style="font-size: 10pt; color: black; font-family: Arial;">dbo</span></p>
</td>
<td style="height: 12.75pt; background-color: transparent; border: #ece9d8; padding: 0in;">
<p class="MsoNormal" style="margin: 6pt;"><span style="font-size: 10pt; color: black; font-family: Arial;">spt_monitor</span></p>
</td>
<td style="height: 12.75pt; background-color: transparent; border: #ece9d8; padding: 0in;">
<p class="MsoNormal" style="margin: 6pt;"><span style="font-size: 10pt; color: black; font-family: Arial;">BASE TABLE</span></p>
</td>
</tr>
<tr style="height: 12.75pt; mso-yfti-irow: 9;">
<td style="height: 12.75pt; background-color: transparent; border: #ece9d8; padding: 0in;">
<p class="MsoNormal" style="margin: 6pt;"><span style="font-size: 10pt; color: black; font-family: Arial;">master</span></p>
</td>
<td style="height: 12.75pt; background-color: transparent; border: #ece9d8; padding: 0in;">
<p class="MsoNormal" style="margin: 6pt;"><span style="font-size: 10pt; color: black; font-family: Arial;">dbo</span></p>
</td>
<td style="height: 12.75pt; background-color: transparent; border: #ece9d8; padding: 0in;">
<p class="MsoNormal" style="margin: 6pt;"><span style="font-size: 10pt; color: black; font-family: Arial;">spt_values</span></p>
</td>
<td style="height: 12.75pt; background-color: transparent; border: #ece9d8; padding: 0in;">
<p class="MsoNormal" style="margin: 6pt;"><span style="font-size: 10pt; color: black; font-family: Arial;">BASE TABLE</span></p>
</td>
</tr>
<tr style="height: 12.75pt; mso-yfti-irow: 10;">
<td style="height: 12.75pt; background-color: transparent; border: #ece9d8; padding: 0in;">
<p class="MsoNormal" style="margin: 6pt;"><span style="font-size: 10pt; color: black; font-family: Arial;">master</span></p>
</td>
<td style="height: 12.75pt; background-color: transparent; border: #ece9d8; padding: 0in;">
<p class="MsoNormal" style="margin: 6pt;"><span style="font-size: 10pt; color: black; font-family: Arial;">dbo</span></p>
</td>
<td style="height: 12.75pt; background-color: transparent; border: #ece9d8; padding: 0in;">
<p class="MsoNormal" style="margin: 6pt;"><span style="font-size: 10pt; color: black; font-family: Arial;">MSreplication_options</span></p>
</td>
<td style="height: 12.75pt; background-color: transparent; border: #ece9d8; padding: 0in;">
<p class="MsoNormal" style="margin: 6pt;"><span style="font-size: 10pt; color: black; font-family: Arial;">BASE TABLE</span></p>
</td>
</tr>
<tr style="height: 12.75pt; mso-yfti-irow: 11;">
<td style="height: 12.75pt; background-color: transparent; border: #ece9d8; padding: 0in;">
<p class="MsoNormal" style="margin: 6pt;"><span style="font-size: 10pt; color: black; font-family: Arial;">master</span></p>
</td>
<td style="height: 12.75pt; background-color: transparent; border: #ece9d8; padding: 0in;">
<p class="MsoNormal" style="margin: 6pt;"><span style="font-size: 10pt; color: black; font-family: Arial;">dbo</span></p>
</td>
<td style="height: 12.75pt; background-color: transparent; border: #ece9d8; padding: 0in;">
<p class="MsoNormal" style="margin: 6pt;"><span style="font-size: 10pt; color: black; font-family: Arial;">DatabasesBackupStrategy</span></p>
</td>
<td style="height: 12.75pt; background-color: transparent; border: #ece9d8; padding: 0in;">
<p class="MsoNormal" style="margin: 6pt;"><span style="font-size: 10pt; color: black; font-family: Arial;">BASE TABLE</span></p>
</td>
</tr>
<tr style="height: 12.75pt; mso-yfti-irow: 12; mso-yfti-lastrow: yes;">
<td style="height: 12.75pt; background-color: transparent; border: #ece9d8; padding: 0in;">
<p class="MsoNormal" style="margin: 6pt;"><span style="font-size: 10pt; color: black; font-family: Arial;">master</span></p>
</td>
<td style="height: 12.75pt; background-color: transparent; border: #ece9d8; padding: 0in;">
<p class="MsoNormal" style="margin: 6pt;"><span style="font-size: 10pt; color: black; font-family: Arial;">dbo</span></p>
</td>
<td style="height: 12.75pt; background-color: transparent; border: #ece9d8; padding: 0in;">
<p class="MsoNormal" style="margin: 6pt;"><span style="font-size: 10pt; color: black; font-family: Arial;">DB_Size</span></p>
</td>
<td style="height: 12.75pt; background-color: transparent; border: #ece9d8; padding: 0in;">
<p class="MsoNormal" style="margin: 6pt;"><span style="font-size: 10pt; color: black; font-family: Arial;">BASE TABLE</span></p>
</td>
</tr>
</tbody>
</table>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="color: green; mso-no-proof: yes;"><span style="font-size: small;"><span style="font-family: Times New Roman;"> </span></span></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="color: green; mso-no-proof: yes;"><span style="font-size: small;"><span style="font-family: Times New Roman;"> </span></span></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; color: blue; font-family: &quot;Courier New&quot;; mso-no-proof: yes;">delete</span><span style="font-size: 10pt; color: black; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"> </span><span style="font-size: 10pt; color: blue; font-family: &quot;Courier New&quot;; mso-no-proof: yes;">top</span><span style="font-size: 10pt; color: black; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"> </span><span style="font-size: 10pt; color: gray; font-family: &quot;Courier New&quot;; mso-no-proof: yes;">(</span><span style="font-size: 10pt; color: black; font-family: &quot;Courier New&quot;; mso-no-proof: yes;">5</span><span style="font-size: 10pt; color: gray; font-family: &quot;Courier New&quot;; mso-no-proof: yes;">)</span><span style="font-size: 10pt; color: black; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"> </span><span style="font-size: 10pt; color: blue; font-family: &quot;Courier New&quot;; mso-no-proof: yes;">from</span><span style="font-size: 10pt; color: black; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"> #temptable</span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; color: gray; font-family: &quot;Courier New&quot;; mso-no-proof: yes;">(</span><span style="font-size: 10pt; color: black; font-family: &quot;Courier New&quot;; mso-no-proof: yes;">5 row</span><span style="font-size: 10pt; color: gray; font-family: &quot;Courier New&quot;; mso-no-proof: yes;">(</span><span style="font-size: 10pt; color: black; font-family: &quot;Courier New&quot;; mso-no-proof: yes;">s</span><span style="font-size: 10pt; color: gray; font-family: &quot;Courier New&quot;; mso-no-proof: yes;">)</span><span style="font-size: 10pt; color: black; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"> affected</span><span style="font-size: 10pt; color: gray; font-family: &quot;Courier New&quot;; mso-no-proof: yes;">)</span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="color: green; mso-no-proof: yes;"><span style="font-size: small;"><span style="font-family: Times New Roman;"> </span></span></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; color: black; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"> </span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; color: blue; font-family: &quot;Courier New&quot;; mso-no-proof: yes;">select</span><span style="font-size: 10pt; color: black; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"> </span><span style="font-size: 10pt; color: gray; font-family: &quot;Courier New&quot;; mso-no-proof: yes;">*</span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; color: black; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span><span style="mso-spacerun: yes;"> </span></span><span style="font-size: 10pt; color: blue; font-family: &quot;Courier New&quot;; mso-no-proof: yes;">from</span><span style="font-size: 10pt; color: black; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"> #temptable</span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="color: black; mso-no-proof: yes;"><span style="font-size: small;"><span style="font-family: Times New Roman;"> </span></span></span></p>
<table class="MsoNormalTable" style="width: 366pt; border-collapse: collapse; mso-padding-alt: 0in 0in 0in 0in;" border="0" cellspacing="0" cellpadding="0" width="488">
<tbody>
<tr style="height: 12.75pt; mso-yfti-irow: 0; mso-yfti-firstrow: yes;">
<td style="width: 91pt; height: 12.75pt; background-color: transparent; border: #ece9d8; padding: 0in;" width="121">
<p class="MsoNormal" style="margin: 6pt;"><strong><span style="font-size: 10pt; color: black; font-family: Arial; mso-bidi-font-size: 12.0pt;">TABLE_CATALOG</span></strong></p>
</td>
<td style="width: 84pt; height: 12.75pt; background-color: transparent; border: #ece9d8; padding: 0in;" width="112">
<p class="MsoNormal" style="margin: 6pt;"><strong><span style="font-size: 10pt; color: black; font-family: Arial; mso-bidi-font-size: 12.0pt;">TABLE_SCHEMA</span></strong></p>
</td>
<td style="width: 124pt; height: 12.75pt; background-color: transparent; border: #ece9d8; padding: 0in;" width="165">
<p class="MsoNormal" style="margin: 6pt;"><strong><span style="font-size: 10pt; color: black; font-family: Arial; mso-bidi-font-size: 12.0pt;">TABLE_NAME</span></strong></p>
</td>
<td style="width: 67pt; height: 12.75pt; background-color: transparent; border: #ece9d8; padding: 0in;" width="89">
<p class="MsoNormal" style="margin: 6pt;"><strong><span style="font-size: 10pt; color: black; font-family: Arial; mso-bidi-font-size: 12.0pt;">TABLE_TYPE</span></strong></p>
</td>
</tr>
<tr style="height: 12.75pt; mso-yfti-irow: 1;">
<td style="height: 12.75pt; background-color: transparent; border: #ece9d8; padding: 0in;">
<p class="MsoNormal" style="margin: 6pt;"><span style="font-size: 10pt; color: black; font-family: Arial;">master</span></p>
</td>
<td style="height: 12.75pt; background-color: transparent; border: #ece9d8; padding: 0in;">
<p class="MsoNormal" style="margin: 6pt;"><span style="font-size: 10pt; color: black; font-family: Arial;">dbo</span></p>
</td>
<td style="height: 12.75pt; background-color: transparent; border: #ece9d8; padding: 0in;">
<p class="MsoNormal" style="margin: 6pt;"><span style="font-size: 10pt; color: black; font-family: Arial;">LogonAudit</span></p>
</td>
<td style="height: 12.75pt; background-color: transparent; border: #ece9d8; padding: 0in;">
<p class="MsoNormal" style="margin: 6pt;"><span style="font-size: 10pt; color: black; font-family: Arial;">BASE TABLE</span></p>
</td>
</tr>
<tr style="height: 12.75pt; mso-yfti-irow: 2;">
<td style="height: 12.75pt; background-color: transparent; border: #ece9d8; padding: 0in;">
<p class="MsoNormal" style="margin: 6pt;"><span style="font-size: 10pt; color: black; font-family: Arial;">master</span></p>
</td>
<td style="height: 12.75pt; background-color: transparent; border: #ece9d8; padding: 0in;">
<p class="MsoNormal" style="margin: 6pt;"><span style="font-size: 10pt; color: black; font-family: Arial;">dbo</span></p>
</td>
<td style="height: 12.75pt; background-color: transparent; border: #ece9d8; padding: 0in;">
<p class="MsoNormal" style="margin: 6pt;"><span style="font-size: 10pt; color: black; font-family: Arial;">DBAobjectCNT</span></p>
</td>
<td style="height: 12.75pt; background-color: transparent; border: #ece9d8; padding: 0in;">
<p class="MsoNormal" style="margin: 6pt;"><span style="font-size: 10pt; color: black; font-family: Arial;">BASE TABLE</span></p>
</td>
</tr>
<tr style="height: 12.75pt; mso-yfti-irow: 3;">
<td style="height: 12.75pt; background-color: transparent; border: #ece9d8; padding: 0in;">
<p class="MsoNormal" style="margin: 6pt;"><span style="font-size: 10pt; color: black; font-family: Arial;">master</span></p>
</td>
<td style="height: 12.75pt; background-color: transparent; border: #ece9d8; padding: 0in;">
<p class="MsoNormal" style="margin: 6pt;"><span style="font-size: 10pt; color: black; font-family: Arial;">dbo</span></p>
</td>
<td style="height: 12.75pt; background-color: transparent; border: #ece9d8; padding: 0in;">
<p class="MsoNormal" style="margin: 6pt;"><span style="font-size: 10pt; color: black; font-family: Arial;">spt_monitor</span></p>
</td>
<td style="height: 12.75pt; background-color: transparent; border: #ece9d8; padding: 0in;">
<p class="MsoNormal" style="margin: 6pt;"><span style="font-size: 10pt; color: black; font-family: Arial;">BASE TABLE</span></p>
</td>
</tr>
<tr style="height: 12.75pt; mso-yfti-irow: 4;">
<td style="height: 12.75pt; background-color: transparent; border: #ece9d8; padding: 0in;">
<p class="MsoNormal" style="margin: 6pt;"><span style="font-size: 10pt; color: black; font-family: Arial;">master</span></p>
</td>
<td style="height: 12.75pt; background-color: transparent; border: #ece9d8; padding: 0in;">
<p class="MsoNormal" style="margin: 6pt;"><span style="font-size: 10pt; color: black; font-family: Arial;">dbo</span></p>
</td>
<td style="height: 12.75pt; background-color: transparent; border: #ece9d8; padding: 0in;">
<p class="MsoNormal" style="margin: 6pt;"><span style="font-size: 10pt; color: black; font-family: Arial;">spt_values</span></p>
</td>
<td style="height: 12.75pt; background-color: transparent; border: #ece9d8; padding: 0in;">
<p class="MsoNormal" style="margin: 6pt;"><span style="font-size: 10pt; color: black; font-family: Arial;">BASE TABLE</span></p>
</td>
</tr>
<tr style="height: 12.75pt; mso-yfti-irow: 5;">
<td style="height: 12.75pt; background-color: transparent; border: #ece9d8; padding: 0in;">
<p class="MsoNormal" style="margin: 6pt;"><span style="font-size: 10pt; color: black; font-family: Arial;">master</span></p>
</td>
<td style="height: 12.75pt; background-color: transparent; border: #ece9d8; padding: 0in;">
<p class="MsoNormal" style="margin: 6pt;"><span style="font-size: 10pt; color: black; font-family: Arial;">dbo</span></p>
</td>
<td style="height: 12.75pt; background-color: transparent; border: #ece9d8; padding: 0in;">
<p class="MsoNormal" style="margin: 6pt;"><span style="font-size: 10pt; color: black; font-family: Arial;">MSreplication_options</span></p>
</td>
<td style="height: 12.75pt; background-color: transparent; border: #ece9d8; padding: 0in;">
<p class="MsoNormal" style="margin: 6pt;"><span style="font-size: 10pt; color: black; font-family: Arial;">BASE TABLE</span></p>
</td>
</tr>
<tr style="height: 12.75pt; mso-yfti-irow: 6;">
<td style="height: 12.75pt; background-color: transparent; border: #ece9d8; padding: 0in;">
<p class="MsoNormal" style="margin: 6pt;"><span style="font-size: 10pt; color: black; font-family: Arial;">master</span></p>
</td>
<td style="height: 12.75pt; background-color: transparent; border: #ece9d8; padding: 0in;">
<p class="MsoNormal" style="margin: 6pt;"><span style="font-size: 10pt; color: black; font-family: Arial;">dbo</span></p>
</td>
<td style="height: 12.75pt; background-color: transparent; border: #ece9d8; padding: 0in;">
<p class="MsoNormal" style="margin: 6pt;"><span style="font-size: 10pt; color: black; font-family: Arial;">DatabasesBackupStrategy</span></p>
</td>
<td style="height: 12.75pt; background-color: transparent; border: #ece9d8; padding: 0in;">
<p class="MsoNormal" style="margin: 6pt;"><span style="font-size: 10pt; color: black; font-family: Arial;">BASE TABLE</span></p>
</td>
</tr>
<tr style="height: 12.75pt; mso-yfti-irow: 7; mso-yfti-lastrow: yes;">
<td style="height: 12.75pt; background-color: transparent; border: #ece9d8; padding: 0in;">
<p class="MsoNormal" style="margin: 6pt;"><span style="font-size: 10pt; color: black; font-family: Arial;">master</span></p>
</td>
<td style="height: 12.75pt; background-color: transparent; border: #ece9d8; padding: 0in;">
<p class="MsoNormal" style="margin: 6pt;"><span style="font-size: 10pt; color: black; font-family: Arial;">dbo</span></p>
</td>
<td style="height: 12.75pt; background-color: transparent; border: #ece9d8; padding: 0in;">
<p class="MsoNormal" style="margin: 6pt;"><span style="font-size: 10pt; color: black; font-family: Arial;">DB_Size</span></p>
</td>
<td style="height: 12.75pt; background-color: transparent; border: #ece9d8; padding: 0in;">
<p class="MsoNormal" style="margin: 6pt;"><span style="font-size: 10pt; color: black; font-family: Arial;">BASE TABLE</span></p>
</td>
</tr>
</tbody>
</table>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-margin-top-alt: auto; mso-margin-bottom-alt: auto;"><span style="font-size: 10pt; color: black; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"> </span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt;"><span style="font-size: small; font-family: Times New Roman;">In SQL 2000, you have to do it a little differently.  I put an ORDER BY in the select statement so you could also see how to delete the &#8221;BOTTOM&#8221; n records.</span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt;"><span style="font-size: small; font-family: Times New Roman;"> </span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; color: blue; font-family: &quot;Courier New&quot;; mso-no-proof: yes;">DELETE</span><span style="font-size: 10pt; color: black; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"> #temptable </span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; color: black; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span><span style="mso-spacerun: yes;"> </span></span><span style="font-size: 10pt; color: blue; font-family: &quot;Courier New&quot;; mso-no-proof: yes;">FROM</span><span style="font-size: 10pt; color: black; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"> </span><span style="font-size: 10pt; color: gray; font-family: &quot;Courier New&quot;; mso-no-proof: yes;">(</span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; color: black; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-tab-count: 1;">      </span></span><span style="font-size: 10pt; color: blue; font-family: &quot;Courier New&quot;; mso-no-proof: yes;">SELECT</span><span style="font-size: 10pt; color: black; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"> </span><span style="font-size: 10pt; color: blue; font-family: &quot;Courier New&quot;; mso-no-proof: yes;">TOP</span><span style="font-size: 10pt; color: black; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"> 4 </span><span style="font-size: 10pt; color: gray; font-family: &quot;Courier New&quot;; mso-no-proof: yes;">*</span><span style="font-size: 10pt; color: black; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"> </span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; color: black; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-tab-count: 1;">      </span><span style="mso-spacerun: yes;"> </span><span style="mso-spacerun: yes;"> </span></span><span style="font-size: 10pt; color: blue; font-family: &quot;Courier New&quot;; mso-no-proof: yes;">FROM</span><span style="font-size: 10pt; color: black; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"> #temptable </span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; color: black; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-tab-count: 1;">      </span><span style="mso-spacerun: yes;"> </span></span><span style="font-size: 10pt; color: blue; font-family: &quot;Courier New&quot;; mso-no-proof: yes;">ORDER</span><span style="font-size: 10pt; color: black; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"> </span><span style="font-size: 10pt; color: blue; font-family: &quot;Courier New&quot;; mso-no-proof: yes;">BY</span><span style="font-size: 10pt; color: black; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"> table_name </span><span style="font-size: 10pt; color: blue; font-family: &quot;Courier New&quot;; mso-no-proof: yes;">desc</span><span style="font-size: 10pt; color: gray; font-family: &quot;Courier New&quot;; mso-no-proof: yes;">)</span><span style="font-size: 10pt; color: black; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"> </span><span style="font-size: 10pt; color: blue; font-family: &quot;Courier New&quot;; mso-no-proof: yes;">AS</span><span style="font-size: 10pt; color: black; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"> t1 </span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; color: blue; font-family: &quot;Courier New&quot;; mso-no-proof: yes;">WHERE</span><span style="font-size: 10pt; color: black; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"> #temptable</span><span style="font-size: 10pt; color: gray; font-family: &quot;Courier New&quot;; mso-no-proof: yes;">.</span><span style="font-size: 10pt; color: black; font-family: &quot;Courier New&quot;; mso-no-proof: yes;">table_name</span><span style="font-size: 10pt; color: gray; font-family: &quot;Courier New&quot;; mso-no-proof: yes;">=</span><span style="font-size: 10pt; color: black; font-family: &quot;Courier New&quot;; mso-no-proof: yes;">t1</span><span style="font-size: 10pt; color: gray; font-family: &quot;Courier New&quot;; mso-no-proof: yes;">.</span><span style="font-size: 10pt; color: black; font-family: &quot;Courier New&quot;; mso-no-proof: yes;">table_name</span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt;"><span style="font-size: 10pt; color: gray; font-family: &quot;Courier New&quot;; mso-no-proof: yes;">(</span><span style="font-size: 10pt; color: black; font-family: &quot;Courier New&quot;; mso-no-proof: yes;">4 row</span><span style="font-size: 10pt; color: gray; font-family: &quot;Courier New&quot;; mso-no-proof: yes;">(</span><span style="font-size: 10pt; color: black; font-family: &quot;Courier New&quot;; mso-no-proof: yes;">s</span><span style="font-size: 10pt; color: gray; font-family: &quot;Courier New&quot;; mso-no-proof: yes;">)</span><span style="font-size: 10pt; color: black; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"> affected</span><span style="font-size: 10pt; color: gray; font-family: &quot;Courier New&quot;; mso-no-proof: yes;">)</span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-margin-top-alt: auto; mso-margin-bottom-alt: auto;"><span style="font-size: 10pt; color: black; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"> </span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; color: blue; font-family: &quot;Courier New&quot;; mso-no-proof: yes;">select</span><span style="font-size: 10pt; color: black; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"> </span><span style="font-size: 10pt; color: gray; font-family: &quot;Courier New&quot;; mso-no-proof: yes;">*</span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-size: 10pt; color: black; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span><span style="mso-spacerun: yes;"> </span></span><span style="font-size: 10pt; color: blue; font-family: &quot;Courier New&quot;; mso-no-proof: yes;">from</span><span style="font-size: 10pt; color: black; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"> #temptable</span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="color: black; mso-no-proof: yes;"><span style="font-size: small;"><span style="font-family: Times New Roman;"> </span></span></span></p>
<table class="MsoNormalTable" style="width: 366pt; border-collapse: collapse; mso-padding-alt: 0in 0in 0in 0in;" border="0" cellspacing="0" cellpadding="0" width="488">
<tbody>
<tr style="height: 12.75pt; mso-yfti-irow: 0; mso-yfti-firstrow: yes;">
<td style="width: 91pt; height: 12.75pt; background-color: transparent; border: #ece9d8; padding: 0in;" width="121">
<p class="MsoNormal" style="margin: 6pt;"><strong><span style="font-size: 10pt; color: black; font-family: Arial; mso-bidi-font-size: 12.0pt;">TABLE_CATALOG</span></strong></p>
</td>
<td style="width: 84pt; height: 12.75pt; background-color: transparent; border: #ece9d8; padding: 0in;" width="112">
<p class="MsoNormal" style="margin: 6pt;"><strong><span style="font-size: 10pt; color: black; font-family: Arial; mso-bidi-font-size: 12.0pt;">TABLE_SCHEMA</span></strong></p>
</td>
<td style="width: 124pt; height: 12.75pt; background-color: transparent; border: #ece9d8; padding: 0in;" width="165">
<p class="MsoNormal" style="margin: 6pt;"><strong><span style="font-size: 10pt; color: black; font-family: Arial; mso-bidi-font-size: 12.0pt;">TABLE_NAME</span></strong></p>
</td>
<td style="width: 67pt; height: 12.75pt; background-color: transparent; border: #ece9d8; padding: 0in;" width="89">
<p class="MsoNormal" style="margin: 6pt;"><strong><span style="font-size: 10pt; color: black; font-family: Arial; mso-bidi-font-size: 12.0pt;">TABLE_TYPE</span></strong></p>
</td>
</tr>
<tr style="height: 12.75pt; mso-yfti-irow: 1;">
<td style="height: 12.75pt; background-color: transparent; border: #ece9d8; padding: 0in;">
<p class="MsoNormal" style="margin: 6pt;"><span style="font-size: 10pt; color: black; font-family: Arial;">master</span></p>
</td>
<td style="height: 12.75pt; background-color: transparent; border: #ece9d8; padding: 0in;">
<p class="MsoNormal" style="margin: 6pt;"><span style="font-size: 10pt; color: black; font-family: Arial;">dbo</span></p>
</td>
<td style="height: 12.75pt; background-color: transparent; border: #ece9d8; padding: 0in;">
<p class="MsoNormal" style="margin: 6pt;"><span style="font-size: 10pt; color: black; font-family: Arial;">DBAobjectCNT</span></p>
</td>
<td style="height: 12.75pt; background-color: transparent; border: #ece9d8; padding: 0in;">
<p class="MsoNormal" style="margin: 6pt;"><span style="font-size: 10pt; color: black; font-family: Arial;">BASE TABLE</span></p>
</td>
</tr>
<tr style="height: 12.75pt; mso-yfti-irow: 2;">
<td style="height: 12.75pt; background-color: transparent; border: #ece9d8; padding: 0in;">
<p class="MsoNormal" style="margin: 6pt;"><span style="font-size: 10pt; color: black; font-family: Arial;">master</span></p>
</td>
<td style="height: 12.75pt; background-color: transparent; border: #ece9d8; padding: 0in;">
<p class="MsoNormal" style="margin: 6pt;"><span style="font-size: 10pt; color: black; font-family: Arial;">dbo</span></p>
</td>
<td style="height: 12.75pt; background-color: transparent; border: #ece9d8; padding: 0in;">
<p class="MsoNormal" style="margin: 6pt;"><span style="font-size: 10pt; color: black; font-family: Arial;">DatabasesBackupStrategy</span></p>
</td>
<td style="height: 12.75pt; background-color: transparent; border: #ece9d8; padding: 0in;">
<p class="MsoNormal" style="margin: 6pt;"><span style="font-size: 10pt; color: black; font-family: Arial;">BASE TABLE</span></p>
</td>
</tr>
<tr style="height: 12.75pt; mso-yfti-irow: 3; mso-yfti-lastrow: yes;">
<td style="height: 12.75pt; background-color: transparent; border: #ece9d8; padding: 0in;">
<p class="MsoNormal" style="margin: 6pt;"><span style="font-size: 10pt; color: black; font-family: Arial;">master</span></p>
</td>
<td style="height: 12.75pt; background-color: transparent; border: #ece9d8; padding: 0in;">
<p class="MsoNormal" style="margin: 6pt;"><span style="font-size: 10pt; color: black; font-family: Arial;">dbo</span></p>
</td>
<td style="height: 12.75pt; background-color: transparent; border: #ece9d8; padding: 0in;">
<p class="MsoNormal" style="margin: 6pt;"><span style="font-size: 10pt; color: black; font-family: Arial;">DB_Size</span></p>
</td>
<td style="height: 12.75pt; background-color: transparent; border: #ece9d8; padding: 0in;">
<p class="MsoNormal" style="margin: 6pt;"><span style="font-size: 10pt; color: black; font-family: Arial;">BASE TABLE</span></p>
</td>
</tr>
</tbody>
</table>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-margin-top-alt: auto; mso-margin-bottom-alt: auto;"><span style="font-size: 10pt; color: black; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"> </span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt;"><span style="font-size: small; font-family: Times New Roman;"> </span></p>
]]></content:encoded>
			<wfw:commentRss>http://rickcaminiti.com/tips/delete-top-records-tsql/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>What recruiters look for in a LinkedIn profile: 8 tips</title>
		<link>http://rickcaminiti.com/tips/what-recruiters-look-for-in-a-linkedin-profile-8-tips/</link>
		<comments>http://rickcaminiti.com/tips/what-recruiters-look-for-in-a-linkedin-profile-8-tips/#comments</comments>
		<pubDate>Mon, 11 May 2009 13:38:27 +0000</pubDate>
		<dc:creator>NothingMan</dc:creator>
				<category><![CDATA[Social]]></category>
		<category><![CDATA[Tips]]></category>
		<category><![CDATA[linkedin]]></category>
		<category><![CDATA[resume]]></category>
		<category><![CDATA[social networking]]></category>

		<guid isPermaLink="false">http://rickcaminiti.com/?p=253</guid>
		<description>This was a great article on LinkedIn that I thought I would share.  I&amp;#8217;ve done most of this and I&amp;#8217;m ALWAYS getting LinkedIn messages for job openings.  It&amp;#8217;s a very valuable resource in this economy!  1. Make your LinkedIn profile 100% complete •    Include all companies, education, and awards. These are the key items on [...]</description>
			<content:encoded><![CDATA[<p>This was a great article on <a href="http://blog.linkedin.com/2009/04/09/matthew-schwartz-msj-grab-recruiters-attention-with-these-8-simple-linkedin-tweaks/" target="_blank">LinkedIn</a> that I thought I would share.  I&#8217;ve done most of this and I&#8217;m ALWAYS getting LinkedIn messages for job openings.  It&#8217;s a very valuable resource in this economy!</p>
<p> <strong>1. Make your LinkedIn profile 100% complete </strong></p>
<p>•    Include all companies, education, and awards. These are the key items on which we recruiters search.<br />
•    References are very important. The more we know about you the better.<br />
•    The more robust your profile, the higher you will be in the Google search rankings.<br />
•    The more information a recruiter has upfront, the more efficient the search process.<br />
•    Update your LinkedIn profile <a href="http://www.linkedin.com/myprofile?trk=tab_pro" target="_blank"><span style="color: #006699;">here</span></a></p>
<p><strong>2. Use a profile picture that you use on multiple sites<br />
</strong></p>
<p>•    A picture helps to create and reinforce your online brand<br />
•    It will help a recruiter identify you on the interview day at “Starbucks”<br />
•    Add a profile picture <a href="http://www.linkedin.com/memberPicture?display=&amp;goback=.prf_en*4US" target="_blank"><span style="color: #006699;">here</span></a></p>
<p><strong>3.  Use the “Specialties” box to fill in keywords<br />
</strong></p>
<p>•    List as many keywords as possible that are relevant to your roles, capabilities, and interests that will help you turn up on LinkedIn Search<br />
•    Update your profile summary and specialties <a href="http://www.linkedin.com/myprofile?displayEditExpertise=&amp;locale=en_US&amp;goback=.prf_en*4US" target="_blank"><span style="color: #006699;">here</span></a></p>
<p><strong>4. Update your LinkedIn “Status” regularly</strong></p>
<p><strong></strong>•    Link to articles you have written or in which you are quoted<br />
•    Update status with your latest blog posts<br />
•    Discuss business accomplishments<br />
•    If you are actively looking for a job, tell people what you are looking for!<br />
•    Update your status on other social networking sites such as Twitter. Try services like ping.fm that allow you to update your status across multiple sites.</p>
<p><strong>5. Make changes to your profile after every job change or promotion<br />
</strong><br />
•    The recruiters you are linked to will notice these changes<br />
•    It is harder to be found if people don’t know where you are<br />
•    Update your LinkedIn profile as you would your change-of-address at the post office</p>
<p><strong>6. Include your web site and blog links<br />
</strong></p>
<p>•    Add suitable weblinks to the “Websites” section on your LinkedIn profile<br />
•    This could range from your career blog to your Twitter profile. Alternatively, you can also link to a guest blog post you wrote recently.<br />
•    Update your “Websites” section <a href="http://www.linkedin.com/myprofile?editAdditionalInfo=&amp;locale=en_US&amp;goback=.prf_en*4US" target="_blank"><span style="color: #006699;">here</span></a></p>
<p><strong>7.  Do not block incoming emails</strong></p>
<p>•    No matter how popular you think you are, you will not be overwhelmed. I promise!<br />
•    The LinkedIn community is all about participation so feel free to accept incoming communication from fellow LinkedIn users. Update your contact settings <a href="https://www.linkedin.com/secure/settings?req=&amp;goback=.aas" target="_blank"><span style="color: #006699;">here</span></a>.<br />
•    If a recruiter reaches out to you and you are not interested, let him or her know or better yet refer a friend<br />
•    LinkedIn actually allows you to control how you receive emails and notifications. Update your settings <a href="https://www.linkedin.com/secure/settings?msgdelivprefs=&amp;goback=.aas" target="_blank"><span style="color: #006699;">here</span></a>.</p>
<p><strong>8. Increase your number of trusted connections!<br />
</strong><br />
•    Use <a href="http://www.linkedin.com/findContacts" target="_blank"><span style="color: #006699;">webmail importer</span></a> to bring your real world professional relationships online and to find your contacts who are already on LinkedIn.<br />
•    Depending on whether you’re a browser person or an Outlook person, check out the <a href="http://www.linkedin.com/static?key=tools" target="_blank"><span style="color: #006699;">respective toolbars</span></a> that will help organize your professional relationship either while you browse or check out your Inbox.</p>
<p>These are just a few tips that I’ve gleaned from my LinkedIn usage over the past year. If you’ve other tips that have helped you as a job seeker reach out to appropriate hiring managers or recruiters, feel free to leave a comment. Hope this helps.</p>
]]></content:encoded>
			<wfw:commentRss>http://rickcaminiti.com/tips/what-recruiters-look-for-in-a-linkedin-profile-8-tips/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss><!-- Dynamic page generated in 1.571 seconds. --><!-- Cached page generated by WP-Super-Cache on 2012-05-17 08:44:16 -->

