<?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>Software Warlock &#187; nested decimal</title>
	<atom:link href="http://softwareblog.morlok.net/tag/nested-decimal/feed/" rel="self" type="application/rss+xml" />
	<link>http://softwareblog.morlok.net</link>
	<description></description>
	<lastBuildDate>Sat, 24 Dec 2011 16:06:59 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1</generator>
		<item>
		<title>Determining SQL Server Version Number</title>
		<link>http://softwareblog.morlok.net/2009/08/03/determining-sql-server-version-number/</link>
		<comments>http://softwareblog.morlok.net/2009/08/03/determining-sql-server-version-number/#comments</comments>
		<pubDate>Mon, 03 Aug 2009 19:12:33 +0000</pubDate>
		<dc:creator>Warlock</dc:creator>
				<category><![CDATA[SQL]]></category>
		<category><![CDATA[nested decimal]]></category>
		<category><![CDATA[version number]]></category>

		<guid isPermaLink="false">http://softwareblog.morlok.net/?p=307</guid>
		<description><![CDATA[I&#8217;ve recently had to write some conditional SQL depending on which version of SQL Server I was running on. This MSDN article shows that for modern versions of SQL Server, the following will get the full version number: SELECT SERVERPROPERTY('productversion'); &#8230;<p class="read-more"><a href="http://softwareblog.morlok.net/2009/08/03/determining-sql-server-version-number/">Read more &#187;</a></p>]]></description>
			<content:encoded><![CDATA[<p>
I&#8217;ve recently had to write some conditional SQL depending on which version of SQL Server I was running on.
</p>
<p><a href="http://support.microsoft.com/kb/321185">This</a> MSDN article shows that for modern versions of SQL Server, the following will get the full version number:</p>
<pre name="code" class="SQL">
SELECT SERVERPROPERTY('productversion');
</pre>
<p>The problem with this is that it is in a string format (FYI you will need to cast it to VARCHAR), and it uses nested decimal notation (e.g. <tt>10.0.1600.22</tt> for SQL Server 2008).  This format is very difficult to reason with, as what I am looking to do is conditionally execute SQL for SQL Server 2000 and for everything else execute some other SQL.  I don&#8217;t care about minor revisions or service packs. To my knowledge, Microsoft does not provide any functions to work with nested decimals.</p>
<p>To make things easier, I constructed the following SQL to pull the major version number out of the string, convert it to an integer, and stick it in a variable:</p>
<pre name="code" class="SQL">
DECLARE @MajorVersion int
SELECT  @MajorVersion = CAST(substring(CAST(SERVERPROPERTY('productversion') AS VARCHAR), 0, Charindex('.', CAST(SERVERPROPERTY('productversion') AS VARCHAR))) AS int);
</pre>
<p>Messy, I know.  If anyone else has a better method, please leave it in the comments.</p>
]]></content:encoded>
			<wfw:commentRss>http://softwareblog.morlok.net/2009/08/03/determining-sql-server-version-number/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>

