﻿<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://developers.de/utility/FeedStylesheets/atom.xsl" media="screen"?><feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en"><title type="html">Senad Hajric</title><subtitle type="html"></subtitle><id>http://developers.de/blogs/senad_hajric/atom.aspx</id><link rel="alternate" type="text/html" href="http://developers.de/blogs/senad_hajric/default.aspx" /><link rel="self" type="application/atom+xml" href="http://developers.de/blogs/senad_hajric/atom.aspx" /><generator uri="http://communityserver.org" version="4.0.30619.63">Community Server</generator><updated>2009-05-25T10:10:00Z</updated><entry><title>BUG: SQL 2008 Express Edition - Stored Procedure sp_DBMaintenance</title><link rel="alternate" type="text/html" href="/blogs/senad_hajric/archive/2009/05/25/bug-sql-2008-express-edition-stored-procedure-sp-dbmaintenance.aspx" /><id>/blogs/senad_hajric/archive/2009/05/25/bug-sql-2008-express-edition-stored-procedure-sp-dbmaintenance.aspx</id><published>2009-05-25T08:10:00Z</published><updated>2009-05-25T08:10:00Z</updated><content type="html">&lt;p&gt;The following error message occurs when you execute the sp_DBMaintenance stored procedure on master database:&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;&amp;quot;Msg 50000, Level 16, State 1, Procedure sp_DBMaintenance, Line 104&lt;br /&gt;SQL2005 or higher is required for sp_expressmaint&amp;quot;&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;The Transact-SQL code for the sp_DBMaintenance stored procedure incorrectly uses the substring for check of server version. The following code in the stored procedure causes the error to occur:&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp; -- check SQL2005 or higher&lt;br /&gt;&amp;nbsp;&amp;nbsp; IF (select SUBSTRING(@@version,(CHARINDEX(&amp;#39;-&amp;#39;,@@version)+2),1))&amp;lt;9&lt;br /&gt;&amp;nbsp;BEGIN&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;RAISERROR(&amp;#39;SQL2005 or higher is required for sp_expressmaint&amp;#39;,16,1)&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; SET @ret = 1&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;GOTO CLEANUP&amp;nbsp;&lt;br /&gt;&amp;nbsp;END&lt;/p&gt;
&lt;p&gt;The length argument of substring is only one character but the version number of sql 2008 is 10 (two characters) therefore return value is less than 9 and error messsage occurs.&lt;br /&gt;&amp;nbsp;&amp;nbsp; &lt;br /&gt;To work around this problem, change the length value to 2. &lt;/p&gt;
&lt;p&gt;SUBSTRING(@@version,(CHARINDEX(&amp;#39;-&amp;#39;,@@version)+2),2)&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://developers.de/aggbug.aspx?PostID=5536" width="1" height="1"&gt;</content><author><name>shajric</name><uri>http://developers.de/members/shajric/default.aspx</uri></author><category term="SQL 2008 Express Edition" scheme="http://developers.de/blogs/senad_hajric/archive/tags/SQL+2008+Express+Edition/default.aspx"></category><category term="sp_DBMaintenance" scheme="http://developers.de/blogs/senad_hajric/archive/tags/sp_5F00_DBMaintenance/default.aspx"></category></entry></feed>