<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>sentient beings &#187; Sql</title>
	<atom:link href="http://www.sentientbeings.com/category/sql/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.sentientbeings.com</link>
	<description>Just another WordPress weblog</description>
	<lastBuildDate>Sun, 06 Jun 2010 08:22:23 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<xhtml:meta xmlns:xhtml="http://www.w3.org/1999/xhtml" name="robots" content="noindex" />
		<item>
		<title>Validating non-US dates in T-SQL</title>
		<link>http://www.sentientbeings.com/2009/11/validating-non-us-dates-in-t-sql/</link>
		<comments>http://www.sentientbeings.com/2009/11/validating-non-us-dates-in-t-sql/#comments</comments>
		<pubDate>Mon, 16 Nov 2009 18:04:32 +0000</pubDate>
		<dc:creator>Kristof</dc:creator>
				<category><![CDATA[Sql]]></category>

		<guid isPermaLink="false">http://www.sentientbeings.com/?p=114</guid>
		<description><![CDATA[For persons not living in the US, date conversion is an every-day issue. While we mostly work around it by using representations of '20091116' for 16 November 2009, the non-geeks have no idea and enter their dates in their local format. For most of the Western-European countries, this would be a sequence of day, month, [...]]]></description>
			<content:encoded><![CDATA[<p>For persons not living in the US, date conversion is an every-day issue. While we mostly work around it by using representations of '20091116' for 16 November 2009, the non-geeks have no idea and enter their dates in their local format. For most of the Western-European countries, this would be a sequence of day, month, year.</p>
<p>It often happens when reading bulk information that dates get treated as text to minimise the amount of conversion errors on the import. I have seen a lot of intricate algorythms to verify the validity of such a string as a date. I have seen people cutting it up by explicitly searching for the separator, storing each part in a different variable, rearranging those variables and then convert the amalgamated strings into a new string which, hopefully, yields a date. I've seen code where the dates get split up, stuck in a table and then rearranged with selects. I believe there is an easier way which simply reads as follows.</p>
<pre class="tsql">&nbsp;
<span style="color: #0000FF;">SET</span> dateformat dmy
&nbsp;
<span style="color: #0000FF;">SELECT</span> <span style="color: #FF0000;">'It'</span><span style="color: #FF0000;">'s a date, cap'</span><span style="color: #FF0000;">'n!'</span>
<span style="color: #0000FF;">FROM</span> tblImport
<span style="color: #0000FF;">WHERE</span> <span style="color: #FF00FF;">ISDATE</span><span style="color: #808080;">&#40;</span>someDateField<span style="color: #808080;">&#41;</span> = <span style="color: #000;">1</span>
&nbsp;</pre>
<p>By using "set dateformat dmy", we tell SQL Server to analyse any possible date by assuming that first part of any date is the day of month, the second is the month and the last part is the year. There are drawbacks, however. You must use either a hyphen or a slash as a separator. You cannot use concatenated date strings or other separators such as periods or blanks.</p>
<p>Still, for us in continental Western-Europe, this solves a lot of problems when reading from bulk imports.</p>


<!-- Begin TwitThis script (http://twitthis.com/) -->
<div class="twitThis">
<script type="text/javascript" src="http://s3.chuug.com/chuug.twitthis.scripts/twitthis.js"></script>
<script type="text/javascript">
<!--
document.write('<a href="javascript:;" onclick="TwitThis.pop();"><img src="http://i14.photobucket.com/albums/a318/intGod/Blog/twitter_icons_24.png" alt="Tweet this"></a>');
//-->
</script>
</div>
<!-- /End -->

<!-- Social Bookmarks BEGIN -->
<div class="social_bookmark">
<a><strong><em><hr></em></strong></a>
<br />
<div class="d">
<br />
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://del.icio.us/post?url=http://www.sentientbeings.com/2009/11/validating-non-us-dates-in-t-sql/&amp;title=Validating+non-US+dates+in+T-SQL" rel="nofollow" title="Add to&nbsp;Del.icio.us"><img class="social_img" src="http://www.sentientbeings.com/wp-content/plugins/social-bookmarks/images/delicious.png" title="Add to&nbsp;Del.icio.us" alt="Add to&nbsp;Del.icio.us" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://digg.com/submit?phase=2&amp;url=http://www.sentientbeings.com/2009/11/validating-non-us-dates-in-t-sql/&amp;title=Validating+non-US+dates+in+T-SQL" rel="nofollow" title="Add to&nbsp;digg"><img class="social_img" src="http://www.sentientbeings.com/wp-content/plugins/social-bookmarks/images/digg.png" title="Add to&nbsp;digg" alt="Add to&nbsp;digg" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.google.com/bookmarks/mark?op=edit&amp;output=popup&amp;bkmk=http://www.sentientbeings.com/2009/11/validating-non-us-dates-in-t-sql/&amp;title=Validating+non-US+dates+in+T-SQL" rel="nofollow" title="Add to&nbsp;Google Bookmarks"><img class="social_img" src="http://www.sentientbeings.com/wp-content/plugins/social-bookmarks/images/google.png" title="Add to&nbsp;Google Bookmarks" alt="Add to&nbsp;Google Bookmarks" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://reddit.com/submit?url=http://www.sentientbeings.com/2009/11/validating-non-us-dates-in-t-sql/&amp;title=Validating+non-US+dates+in+T-SQL" rel="nofollow" title="Add to&nbsp;reddit"><img class="social_img" src="http://www.sentientbeings.com/wp-content/plugins/social-bookmarks/images/reddit.png" title="Add to&nbsp;reddit" alt="Add to&nbsp;reddit" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://slashdot.org/bookmark.pl?url=http://www.sentientbeings.com/2009/11/validating-non-us-dates-in-t-sql/&amp;title=Validating+non-US+dates+in+T-SQL" rel="nofollow" title="Add to&nbsp;Slashdot"><img class="social_img" src="http://www.sentientbeings.com/wp-content/plugins/social-bookmarks/images/slashdot.png" title="Add to&nbsp;Slashdot" alt="Add to&nbsp;Slashdot" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.stumbleupon.com/submit.php?url=http://www.sentientbeings.com/2009/11/validating-non-us-dates-in-t-sql/&amp;title=Validating+non-US+dates+in+T-SQL" rel="nofollow" title="Add to&nbsp;Stumble Upon"><img class="social_img" src="http://www.sentientbeings.com/wp-content/plugins/social-bookmarks/images/stumbleupon.png" title="Add to&nbsp;Stumble Upon" alt="Add to&nbsp;Stumble Upon" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.technorati.com/faves?add=http://www.sentientbeings.com/2009/11/validating-non-us-dates-in-t-sql/" rel="nofollow" title="Add to&nbsp;Technorati"><img class="social_img" src="http://www.sentientbeings.com/wp-content/plugins/social-bookmarks/images/technorati.png" title="Add to&nbsp;Technorati" alt="Add to&nbsp;Technorati" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://myweb2.search.yahoo.com/myresults/bookmarklet?u=http://www.sentientbeings.com/2009/11/validating-non-us-dates-in-t-sql/&amp;t=Validating+non-US+dates+in+T-SQL" rel="nofollow" title="Add to&nbsp;Yahoo My Web"><img class="social_img" src="http://www.sentientbeings.com/wp-content/plugins/social-bookmarks/images/yahoo.png" title="Add to&nbsp;Yahoo My Web" alt="Add to&nbsp;Yahoo My Web" /></a>
<br />
</div>
</div>
<!-- Social Bookmarks END -->
]]></content:encoded>
			<wfw:commentRss>http://www.sentientbeings.com/2009/11/validating-non-us-dates-in-t-sql/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Using SELECT instead of conditionals with variables</title>
		<link>http://www.sentientbeings.com/2009/11/using-select-instead-of-conditionals-with-variables/</link>
		<comments>http://www.sentientbeings.com/2009/11/using-select-instead-of-conditionals-with-variables/#comments</comments>
		<pubDate>Mon, 16 Nov 2009 17:35:45 +0000</pubDate>
		<dc:creator>Kristof</dc:creator>
				<category><![CDATA[Sql]]></category>

		<guid isPermaLink="false">http://www.sentientbeings.com/?p=105</guid>
		<description><![CDATA[You may have found yourself coding something like this in a Stored Procedure.
&#160;
IF @pCode = 'AA' or @pCode = 'AB' or @pCode = 'BA' or @pCode = 'XY'
	SET @actionType = 'single'
ELSE
	SET @actionType = 'combined'
&#160;
You can recode this to SQL to make it more readable.
The second option will be slower - about four times slower - [...]]]></description>
			<content:encoded><![CDATA[<p>You may have found yourself coding something like this in a Stored Procedure.</p>
<pre class="tsql">&nbsp;
<span style="color: #0000FF;">IF</span> @pCode = <span style="color: #FF0000;">'AA'</span> or @pCode = <span style="color: #FF0000;">'AB'</span> or @pCode = <span style="color: #FF0000;">'BA'</span> or @pCode = <span style="color: #FF0000;">'XY'</span>
	<span style="color: #0000FF;">SET</span> @actionType = <span style="color: #FF0000;">'single'</span>
<span style="color: #0000FF;">ELSE</span>
	<span style="color: #0000FF;">SET</span> @actionType = <span style="color: #FF0000;">'combined'</span>
&nbsp;</pre>
<p>You can recode this to SQL to make it more readable.</p>
<p>The second option will be slower - about four times slower - but on my stone-age development system, it still performed 20000 iterations in under 200ms. That's 100000 comparisons per second. </p>
<pre class="tsql">&nbsp;
<span style="color: #0000FF;">SELECT</span>
	@actionType = <span style="color: #FF0000;">'combined'</span>
&nbsp;
<span style="color: #0000FF;">SELECT</span>
	@actionType = <span style="color: #FF0000;">'single'</span>
<span style="color: #0000FF;">WHERE</span>
	@pCode in
		<span style="color: #808080;">&#40;</span>
			<span style="color: #FF0000;">'AA'</span>,
			<span style="color: #FF0000;">'AB'</span>,
			<span style="color: #FF0000;">'BA'</span>,
			<span style="color: #FF0000;">'XY'</span>
		<span style="color: #808080;">&#41;</span>
&nbsp;</pre>


<!-- Begin TwitThis script (http://twitthis.com/) -->
<div class="twitThis">
<script type="text/javascript" src="http://s3.chuug.com/chuug.twitthis.scripts/twitthis.js"></script>
<script type="text/javascript">
<!--
document.write('<a href="javascript:;" onclick="TwitThis.pop();"><img src="http://i14.photobucket.com/albums/a318/intGod/Blog/twitter_icons_24.png" alt="Tweet this"></a>');
//-->
</script>
</div>
<!-- /End -->

<!-- Social Bookmarks BEGIN -->
<div class="social_bookmark">
<a><strong><em><hr></em></strong></a>
<br />
<div class="d">
<br />
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://del.icio.us/post?url=http://www.sentientbeings.com/2009/11/using-select-instead-of-conditionals-with-variables/&amp;title=Using+SELECT+instead+of+conditionals+with+variables" rel="nofollow" title="Add to&nbsp;Del.icio.us"><img class="social_img" src="http://www.sentientbeings.com/wp-content/plugins/social-bookmarks/images/delicious.png" title="Add to&nbsp;Del.icio.us" alt="Add to&nbsp;Del.icio.us" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://digg.com/submit?phase=2&amp;url=http://www.sentientbeings.com/2009/11/using-select-instead-of-conditionals-with-variables/&amp;title=Using+SELECT+instead+of+conditionals+with+variables" rel="nofollow" title="Add to&nbsp;digg"><img class="social_img" src="http://www.sentientbeings.com/wp-content/plugins/social-bookmarks/images/digg.png" title="Add to&nbsp;digg" alt="Add to&nbsp;digg" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.google.com/bookmarks/mark?op=edit&amp;output=popup&amp;bkmk=http://www.sentientbeings.com/2009/11/using-select-instead-of-conditionals-with-variables/&amp;title=Using+SELECT+instead+of+conditionals+with+variables" rel="nofollow" title="Add to&nbsp;Google Bookmarks"><img class="social_img" src="http://www.sentientbeings.com/wp-content/plugins/social-bookmarks/images/google.png" title="Add to&nbsp;Google Bookmarks" alt="Add to&nbsp;Google Bookmarks" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://reddit.com/submit?url=http://www.sentientbeings.com/2009/11/using-select-instead-of-conditionals-with-variables/&amp;title=Using+SELECT+instead+of+conditionals+with+variables" rel="nofollow" title="Add to&nbsp;reddit"><img class="social_img" src="http://www.sentientbeings.com/wp-content/plugins/social-bookmarks/images/reddit.png" title="Add to&nbsp;reddit" alt="Add to&nbsp;reddit" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://slashdot.org/bookmark.pl?url=http://www.sentientbeings.com/2009/11/using-select-instead-of-conditionals-with-variables/&amp;title=Using+SELECT+instead+of+conditionals+with+variables" rel="nofollow" title="Add to&nbsp;Slashdot"><img class="social_img" src="http://www.sentientbeings.com/wp-content/plugins/social-bookmarks/images/slashdot.png" title="Add to&nbsp;Slashdot" alt="Add to&nbsp;Slashdot" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.stumbleupon.com/submit.php?url=http://www.sentientbeings.com/2009/11/using-select-instead-of-conditionals-with-variables/&amp;title=Using+SELECT+instead+of+conditionals+with+variables" rel="nofollow" title="Add to&nbsp;Stumble Upon"><img class="social_img" src="http://www.sentientbeings.com/wp-content/plugins/social-bookmarks/images/stumbleupon.png" title="Add to&nbsp;Stumble Upon" alt="Add to&nbsp;Stumble Upon" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.technorati.com/faves?add=http://www.sentientbeings.com/2009/11/using-select-instead-of-conditionals-with-variables/" rel="nofollow" title="Add to&nbsp;Technorati"><img class="social_img" src="http://www.sentientbeings.com/wp-content/plugins/social-bookmarks/images/technorati.png" title="Add to&nbsp;Technorati" alt="Add to&nbsp;Technorati" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://myweb2.search.yahoo.com/myresults/bookmarklet?u=http://www.sentientbeings.com/2009/11/using-select-instead-of-conditionals-with-variables/&amp;t=Using+SELECT+instead+of+conditionals+with+variables" rel="nofollow" title="Add to&nbsp;Yahoo My Web"><img class="social_img" src="http://www.sentientbeings.com/wp-content/plugins/social-bookmarks/images/yahoo.png" title="Add to&nbsp;Yahoo My Web" alt="Add to&nbsp;Yahoo My Web" /></a>
<br />
</div>
</div>
<!-- Social Bookmarks END -->
]]></content:encoded>
			<wfw:commentRss>http://www.sentientbeings.com/2009/11/using-select-instead-of-conditionals-with-variables/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
