﻿<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://developers.de/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Senad Hajric</title><link />http://developers.de/blogs/senad_hajric/default.aspx<description></description><dc:language>en</dc:language><generator>CommunityServer 2008 SP1 (Build: 30619.63)</generator><item><title>BUG: SQL 2008 Express Edition - Stored Procedure sp_DBMaintenance</title><link />http://developers.de/blogs/senad_hajric/archive/2009/05/25/bug-sql-2008-express-edition-stored-procedure-sp-dbmaintenance.aspx<pubdate>Mon, 25 May 2009 08:10:00 GMT</pubdate><guid ispermalink="false">7e491611-45ad-4dae-a68f-c4cb64439510:5536</guid><dc:creator>shajric</dc:creator><slash:comments>1</slash:comments><wfw:commentrss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://developers.de/blogs/senad_hajric/rsscomments.aspx?PostID=5536</wfw:commentrss><comments>http://developers.de/blogs/senad_hajric/archive/2009/05/25/bug-sql-2008-express-edition-stored-procedure-sp-dbmaintenance.aspx#comments</comments><description>&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;</description><category domain="http://developers.de/blogs/senad_hajric/archive/tags/SQL+2008+Express+Edition/default.aspx">SQL 2008 Express Edition</category><category domain="http://developers.de/blogs/senad_hajric/archive/tags/sp_5F00_DBMaintenance/default.aspx">sp_DBMaintenance</category></item></channel></rss>