<feed xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns="http://www.w3.org/2005/Atom" xml:lang="nl-NL">
    <title>Ambition IT - Weblog</title>
    <link rel="self" type="application/atom+xml" href="http://blog.ambitionit.nl/Atom.aspx" />
    <subtitle type="html">SQL Server</subtitle>
    <id>http://blog.ambitionit.nl/Default.aspx</id>
    <author>
        <name>HJ</name>
        <uri>http://blog.ambitionit.nl/Default.aspx</uri>
    </author>
    <generator uri="http://subtextproject.com" version="Subtext Version 2.1.1.1">Subtext</generator>
    <updated>2011-12-21T08:53:09Z</updated>
    <entry>
        <title>Ambition IT sponsort SQL Zaterdag</title>
        <link rel="alternate" type="text/html" href="http://blog.ambitionit.nl/archive/2011/03/31/ambition-it-sponsort-sql-zaterdag.aspx" />
        <id>http://blog.ambitionit.nl/archive/2011/03/31/ambition-it-sponsort-sql-zaterdag.aspx</id>
        <published>2011-03-31T14:50:27Z</published>
        <updated>2011-12-21T08:52:50Z</updated>
        <summary type="html">Ambition IT sponsort SQL Zaterdag op 2 april 2011! Zie www.sqlzaterdag.nl.</summary>
        <content type="html">Ambition IT sponsort SQL Zaterdag op 2 april 2011! Zie &lt;a target="_blank" href="http://www.sqlzaterdag.nl"&gt;www.sqlzaterdag.nl&lt;/a&gt;&lt;a&gt;.&lt;br /&gt;
&lt;/a&gt;&lt;img src="http://blog.ambitionit.nl/aggbug/38.aspx" width="1" height="1" /&gt;</content>
    </entry>
    <entry>
        <title>Key management services (KMS) host could not be located ...</title>
        <link rel="alternate" type="text/html" href="http://blog.ambitionit.nl/archive/2010/10/05/key-management-services-kms-host-could-not-be-located.aspx" />
        <id>http://blog.ambitionit.nl/archive/2010/10/05/key-management-services-kms-host-could-not-be-located.aspx</id>
        <published>2010-10-05T10:57:46Z</published>
        <updated>2011-12-21T08:53:02Z</updated>
        <summary type="html">We installed a new Windows Server 2008 server and were not able to activate online. Thanks to Code-Journey we found the easiest way to fix this: just retype your key.</summary>
        <content type="html">&lt;p&gt;We installed a new Windows Server 2008 server and were not able to activate online. The activation gave this error message:&lt;/p&gt;
&lt;pre&gt;Key management services (KMS) host could not be located in domain name system (DNS),&lt;br /&gt;please have your system administrator verify that a kms is published correctly in dns.&lt;br /&gt;0X8007232B.&lt;/pre&gt;
&lt;p&gt;This post by &lt;a target="_blank" href="http://code-journey.com/2009/08/21/key-management-services-kms-host-could-not-be-located-in-domain-name-system-dns-08007232b-mak-kms/comment-page-1/#comment-2836"&gt;Code-Journey&lt;/a&gt; showed the easiest way to fix this problem: just retype your key.&lt;/p&gt;
&lt;p&gt;"&lt;font face=""&gt;It is stated on Microsoft.com to be an error related to trying to activate a Multiple Activation Key(MAK) while not having access to a Key Management Service (KMS).&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;&lt;font face=""&gt;If you have your volume license key (MAK) all you have to do is go to “Control Panel” -&amp;gt; “System” -&amp;gt; “Change Product key”,&lt;br /&gt;
and insert the key. Even if you did it during installation!"&lt;br /&gt;
&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;&lt;font face=""&gt;Thank you, Code-Journey!&lt;/font&gt;&lt;/p&gt;&lt;img src="http://blog.ambitionit.nl/aggbug/36.aspx" width="1" height="1" /&gt;</content>
    </entry>
    <entry>
        <title>Wij zoeken een .Net developer</title>
        <link rel="alternate" type="text/html" href="http://blog.ambitionit.nl/archive/2010/09/24/wij-zoeken-een-.net-developer.aspx" />
        <id>http://blog.ambitionit.nl/archive/2010/09/24/wij-zoeken-een-.net-developer.aspx</id>
        <published>2010-09-24T15:08:09Z</published>
        <updated>2011-12-21T08:53:09Z</updated>
        <summary type="html">Ambition IT is op zoek naar een .Net developer! Zie http://ambitionit.heeft-vacatures.nl/.</summary>
        <content type="html">&lt;p&gt;Ambition IT is op zoek naar een .Net developer! Zie &lt;font face=""&gt;&lt;a href="http://ambitionit.heeft-vacatures.nl/"&gt;http://ambitionit.heeft-vacatures.nl/&lt;/a&gt;.&lt;/font&gt;&lt;/p&gt;&lt;img src="http://blog.ambitionit.nl/aggbug/35.aspx" width="1" height="1" /&gt;</content>
    </entry>
    <entry>
        <title>5 oktober 2010: Donald Farmer bij PASS Nederland</title>
        <link rel="alternate" type="text/html" href="http://blog.ambitionit.nl/archive/2010/09/24/5-oktober-2010-donald-farmer-bij-pass-nederland.aspx" />
        <id>http://blog.ambitionit.nl/archive/2010/09/24/5-oktober-2010-donald-farmer-bij-pass-nederland.aspx</id>
        <published>2010-09-24T12:46:19Z</published>
        <updated>2010-09-24T12:46:19Z</updated>
        <summary type="html">Op 5 oktober 2010 is Donald Farmer gastspreker bij onze maandelijkse PASS - bijeenkomst! Zie www.sqlpass.nl voor meer details.</summary>
        <content type="html">&lt;p&gt;Op 5 oktober 2010 is Donald Farmer gastspreker bij onze maandelijkse PASS - bijeenkomst! Zie &lt;font face=""&gt;&lt;a href="http://www.sqlpass.nl"&gt;www.sqlpass.nl&lt;/a&gt; voor meer details.&lt;/font&gt;&lt;/p&gt;&lt;img src="http://blog.ambitionit.nl/aggbug/34.aspx" width="1" height="1" /&gt;</content>
    </entry>
    <entry>
        <title>SQL Zaterdag 23 oktober 2010: Inschrijving geopend</title>
        <link rel="alternate" type="text/html" href="http://blog.ambitionit.nl/archive/2010/09/21/sql-zaterdag-23-oktober-2010-inschrijving-geopend.aspx" />
        <id>http://blog.ambitionit.nl/archive/2010/09/21/sql-zaterdag-23-oktober-2010-inschrijving-geopend.aspx</id>
        <published>2010-09-21T08:29:52Z</published>
        <updated>2010-09-21T08:29:52Z</updated>
        <summary type="html">De inschrijving voor SQL Zaterdag op 23 oktober 2010 is geopend! Zie http://sqlzaterdag.eventbrite.com.</summary>
        <content type="html">De inschrijving voor SQL Zaterdag op 23 oktober 2010 is geopend! Zie &lt;a href="http://sqlzaterdag.eventbrite.com/"&gt;http://sqlzaterdag.eventbrite.com&lt;/a&gt;.&lt;img src="http://blog.ambitionit.nl/aggbug/33.aspx" width="1" height="1" /&gt;</content>
    </entry>
    <entry>
        <title>Error when changing the collation of a database</title>
        <link rel="alternate" type="text/html" href="http://blog.ambitionit.nl/archive/2010/09/16/error-when-changing-the-collation-of-a-database.aspx" />
        <id>http://blog.ambitionit.nl/archive/2010/09/16/error-when-changing-the-collation-of-a-database.aspx</id>
        <published>2010-09-16T15:56:03Z</published>
        <updated>2010-09-16T15:57:59Z</updated>
        <summary type="html">Recently I had to change the collation of a database. That resulted in an error message: The database could not be exclusively locked to perform the operation.</summary>
        <content type="html">&lt;p&gt;Recently I had to change the collation of a database. That resulted in an error message:&lt;/p&gt;
&lt;pre&gt;The database could not be exclusively locked to perform the operation.&lt;/pre&gt;
&lt;p&gt;I found the solution at &lt;font face=""&gt;&lt;a href="http://www.stolenbit.com/2008/10/database-could-not-be-exclusively.html"&gt;http://www.stolenbit.com/2008/10/database-could-not-be-exclusively.html&lt;/a&gt;. &lt;/font&gt;To change the collation in this case you have to put the database in single user mode first:&lt;/p&gt;
&lt;pre&gt;ALTER DATABASE &amp;lt;database_name&amp;gt; SET SINGLE_USER WITH ROLLBACK IMMEDIATE &lt;br /&gt;ALTER DATABASE &amp;lt;database_name&amp;gt; COLLATE &amp;lt;target_collation_name like SQL_Latin1_General_CP1_CI_AS&amp;gt;&lt;br /&gt;ALTER DATABASE &amp;lt;database_name&amp;gt; SET MULTI_USER&lt;/pre&gt;
&lt;p&gt;Kimberly Tripp has more on this subject at &lt;a href="http://www.sqlskills.com/BLOGS/KIMBERLY/post/Changing-Database-Collation-and-dealing-with-TempDB-Objects.aspx"&gt;http://www.sqlskills.com/BLOGS/KIMBERLY/post/Changing-Database-Collation-and-dealing-with-TempDB-Objects.aspx&lt;/a&gt;.&lt;/p&gt;&lt;img src="http://blog.ambitionit.nl/aggbug/31.aspx" width="1" height="1" /&gt;</content>
    </entry>
    <entry>
        <title>SQL Zaterdag 2010 / SQL Saturday in the Netherlands</title>
        <link rel="alternate" type="text/html" href="http://blog.ambitionit.nl/archive/2010/09/16/sql-zaterdag-2010-komt-eraan.aspx" />
        <id>http://blog.ambitionit.nl/archive/2010/09/16/sql-zaterdag-2010-komt-eraan.aspx</id>
        <published>2010-09-16T15:22:06Z</published>
        <updated>2010-09-16T15:22:32Z</updated>
        <summary type="html">Aimed at a Dutch audience: The second SQL Saturday in The Netherlands is on it's way! Be there on October 23.

Read more information at www.sqlzaterdag.nl.</summary>
        <content type="html">&lt;p&gt;Aimed at a Dutch audience: The second SQL Saturday in The Netherlands is on it's way! Be there on October 23.&lt;/p&gt;
&lt;p&gt;Read more information at &lt;a href="http://www.sqlzaterdag.nl"&gt;www.sqlzaterdag.nl&lt;/a&gt;.&lt;/p&gt;&lt;img src="http://blog.ambitionit.nl/aggbug/30.aspx" width="1" height="1" /&gt;</content>
    </entry>
    <entry>
        <title>Delete Maintance Plan without SSIS installed</title>
        <link rel="alternate" type="text/html" href="http://blog.ambitionit.nl/archive/2010/09/15/delete-maintance-plan-without-ssis-installed.aspx" />
        <id>http://blog.ambitionit.nl/archive/2010/09/15/delete-maintance-plan-without-ssis-installed.aspx</id>
        <published>2010-09-15T14:08:25Z</published>
        <updated>2010-09-15T14:08:25Z</updated>
        <summary type="html">Today I ran into an interesting problem. I wanted to delete a Maintenance Plan on a server that had SQL Server reinstalled without SSIS (Integration Services). (I was not responsible for this reinstallation...).</summary>
        <content type="html">&lt;p&gt;&lt;font face=""&gt;Today I ran into an interesting problem. I wanted to delete a Maintenance Plan on a server that had SQL Server reinstalled without SSIS (Integration Services). (I was not responsible for this reinstallation...).&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;&lt;font face=""&gt;I did not know that yet when I wanted to delete the Maintenance Plan. So I followed the menu (right-click the Maintenance Plan and select Modify) and I got this error:&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;&lt;img alt="" width="678" height="424" src="/images/blog_ambitionit_nl/BlogPictures/20100915MaintenancePlanError.jpg" /&gt;&lt;/p&gt;
&lt;br /&gt;
&lt;h3&gt;The error message in plain text for the search engines:&lt;/h3&gt;
&lt;p&gt;&lt;font face="Courier New"&gt;Exception has been thrown by the target of an invocation. (mscorlib)&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;&lt;font face="Courier New"&gt;&lt;strong&gt;Additional information:&lt;br /&gt;
&lt;/strong&gt;An Integration Services class cannot be found. Make sure that Integration Services is correctly installed on the computer that is running the application. Also, make sure that the 64-bit version of Integration Services is installed if you are running a 64-bit application.&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;&lt;font face="Courier New"&gt;Class not registered.&lt;/font&gt;&lt;/p&gt;
&lt;h3&gt;T-SQL&lt;/h3&gt;
&lt;font face=""&gt;
&lt;p&gt;I then searched for and found the T-SQL code for deleting the Maintenance Plan manually:&lt;/p&gt;
&lt;p&gt;&lt;font face="Courier New"&gt;/* Delete a Maintenance Plan manually.&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;&lt;font face="Courier New"&gt; Works in SQL Server 2005 and SQL Server 2008. */&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;&lt;font face="Courier New"&gt;--To get the Maintenance Plan IDs:&lt;br /&gt;
USE msdb&lt;br /&gt;
GO&lt;br /&gt;
SELECT * FROM sysmaintplan_plans&lt;br /&gt;
GO&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;&lt;font face="Courier New"&gt;USE msdb&lt;br /&gt;
GO&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;&lt;font face="Courier New"&gt;DECLARE @varID varchar(100)&lt;br /&gt;
--Paste the ID of the Maintenance Plan you want to delete below&lt;br /&gt;
SET @varID ='E13A5028-A35C-43BE-96C0-46B436CCDBB5' &lt;br /&gt;
DELETE FROM sysmaintplan_log WHERE plan_id = @varID&lt;br /&gt;
DELETE FROM sysmaintplan_subplans WHERE plan_id = @varID&lt;br /&gt;
DELETE FROM sysmaintplan_plans WHERE id = @varID&lt;br /&gt;
GO&lt;/font&gt;&lt;/p&gt;
&lt;h3&gt;References&lt;/h3&gt;
&lt;p&gt;I found the code in this thread: &lt;a href="http://www.eggheadcafe.com/software/aspnet/33774157/cannot-delete-maintenance-plan-or-scheduled-job.aspx"&gt;http://www.eggheadcafe.com/software/aspnet/33774157/cannot-delete-maintenance-plan-or-scheduled-job.aspx&lt;/a&gt;.&lt;/p&gt;
&lt;/font&gt;&lt;img src="http://blog.ambitionit.nl/aggbug/29.aspx" width="1" height="1" /&gt;</content>
    </entry>
    <entry>
        <title>Show / hide text, notes, images in Reporting Services with a report parameter</title>
        <link rel="alternate" type="text/html" href="http://blog.ambitionit.nl/archive/2010/08/30/show-hide-text-notes-images-in-reporting-services-with.aspx" />
        <id>http://blog.ambitionit.nl/archive/2010/08/30/show-hide-text-notes-images-in-reporting-services-with.aspx</id>
        <published>2010-08-30T15:10:50Z</published>
        <updated>2010-08-30T15:14:44Z</updated>
        <summary type="html">Reports usually contain some kind of explanation, mostly at the end of the report. The bigger the report, or the more complex the report, the longer the explanation. And you may not want to print this extra text on every occasion, e.g. for saving the paper, the environment and your wallet.</summary>
        <content type="html">&lt;p&gt;&lt;font face=""&gt;Reports usually contain some kind of explanation, mostly at the end of the report. The bigger the report, or the more complex the report, the longer the explanation. And you may not want to print this extra text on every occasion, e.g. for saving the paper, the environment and your wallet.&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;&lt;font face=""&gt;A way to do this is by using a report parameter. This parameter typically defaults to 'do not show' and the user can simply change this to 'show'.&lt;/font&gt;&lt;/p&gt;
&lt;h3&gt;Define the parameter&lt;/h3&gt;
&lt;p&gt;&lt;font face=""&gt;Define the parameter as shown in the image.&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;&lt;img alt="" width="498" height="386" src="/images/blog_ambitionit_nl/BlogPictures/20100830_ShowHideExplanation_1.jpg" /&gt;&lt;font face=""&gt; &lt;/font&gt;&lt;/p&gt;
&lt;h3&gt;
&lt;p&gt;Define the Hidden property of the text, notes, image&lt;/p&gt;
&lt;/h3&gt;
&lt;p&gt;In the Hidden property set =Iif(Parameters!varExplanation.Value = 1, False, True).&lt;/p&gt;
&lt;p&gt;&lt;img alt="" src="/images/blog_ambitionit_nl/BlogPictures/20100830_ShowHideExplanation_2.jpg" /&gt;&lt;font face=""&gt; &lt;/font&gt;&lt;/p&gt;
&lt;h3&gt;Result&lt;/h3&gt;
&lt;p&gt;The result is that:&lt;/p&gt;
&lt;ol&gt;
    &lt;li&gt;By default the text, notes, image are not shown.&lt;/li&gt;
    &lt;li&gt;The user can choose to show the text, notes, image.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;&lt;img alt="" width="293" height="79" src="/images/blog_ambitionit_nl/BlogPictures/20100830_ShowHideExplanation_3.jpg" /&gt;&lt;/p&gt;&lt;img src="http://blog.ambitionit.nl/aggbug/28.aspx" width="1" height="1" /&gt;</content>
    </entry>
    <entry>
        <title>Execute a command against all tables in a database</title>
        <link rel="alternate" type="text/html" href="http://blog.ambitionit.nl/archive/2010/07/06/execute-a-command-against-all-tables-in-a-database.aspx" />
        <id>http://blog.ambitionit.nl/archive/2010/07/06/execute-a-command-against-all-tables-in-a-database.aspx</id>
        <published>2010-07-06T18:15:35Z</published>
        <updated>2010-07-06T18:15:35Z</updated>
        <summary type="html">Have you ever wanted to execute a command againts all tables in your database? And did you struggle with cursors or WHILE BEGIN ... END loops?

So did I. Until I discovered the undocumented stored procedure sp_MSforeachtable and I love it.</summary>
        <content type="html">&lt;p&gt;Have you ever wanted to execute a command againts all tables in your database? And did you struggle with cursors or WHILE BEGIN ... END loops?&lt;/p&gt;
&lt;p&gt;So did I. Until I discovered the undocumented stored procedure sp_MSforeachtable and I love it.&lt;/p&gt;
&lt;p&gt;I now use it for rebuilding all indexes on all tables. The syntax is&lt;/p&gt;
&lt;pre&gt;sp_MSforeachtable &amp;lt;command&amp;gt;&lt;/pre&gt;
&lt;p&gt;In the command you use a question mark (?) as a placeholder for the table name. So for rebuilding all indexes on all tables in a database you would use the following command:&lt;/p&gt;
&lt;pre&gt;sp_MSforeachtable 'ALTER INDEX ALL ON ? REBUILD WITH (FILLFACTOR = 80)'&lt;/pre&gt;
&lt;h3&gt;Is it really undocumented?&lt;/h3&gt;
&lt;p&gt;Well, you can find details with EXEC sp_helptext sp_MSforeachtable:&lt;/p&gt;
&lt;pre&gt;create proc sys.sp_MSforeachtable  &lt;br /&gt; @command1 nvarchar(2000), @replacechar nchar(1) = N'?', @command2 nvarchar(2000) = null,  &lt;br /&gt;   @command3 nvarchar(2000) = null, @whereand nvarchar(2000) = null,  &lt;br /&gt; @precommand nvarchar(2000) = null, @postcommand nvarchar(2000) = null  &lt;br /&gt;as  &lt;br /&gt; /* This proc returns one or more rows for each table (optionally, matching @where), with each table defaulting to its own result set */  &lt;br /&gt; /* @precommand and @postcommand may be used to force a single result set via a temp table. */  &lt;br /&gt;  &lt;br /&gt; /* Preprocessor won't replace within quotes so have to use str(). */  &lt;br /&gt; declare @mscat nvarchar(12)  &lt;br /&gt; select @mscat = ltrim(str(convert(int, 0x0002)))  &lt;br /&gt;  &lt;br /&gt; if (@precommand is not null)  &lt;br /&gt;  exec(@precommand)  &lt;br /&gt;  &lt;br /&gt; /* Create the select */  &lt;br /&gt;   exec(N'declare hCForEachTable cursor global for select ''['' + REPLACE(schema_name(syso.schema_id), N'']'', N'']]'') + '']'' + ''.'' + ''['' + REPLACE(object_name(o.id), N'']'', N'']]'') + '']'' from dbo.sysobjects o join sys.all_objects syso on o.id =&lt;br /&gt; syso.object_id '  &lt;br /&gt;         + N' where OBJECTPROPERTY(o.id, N''IsUserTable'') = 1 ' + N' and o.category &amp;amp; ' + @mscat + N' = 0 '  &lt;br /&gt;         + @whereand)  &lt;br /&gt; declare @retval int  &lt;br /&gt; select @retval = @@error  &lt;br /&gt; if (@retval = 0)  &lt;br /&gt;  exec @retval = sys.sp_MSforeach_worker @command1, @replacechar, @command2, @command3, 0  &lt;br /&gt;  &lt;br /&gt; if (@retval = 0 and @postcommand is not null)  &lt;br /&gt;  exec(@postcommand)  &lt;br /&gt;  &lt;br /&gt; return @retval  &lt;/pre&gt;
&lt;h3&gt;sp_MSforeachdb&lt;/h3&gt;
&lt;p&gt;A related undocumented stored procedure is sp_MSforeachdb. EXEC sp_helptext sp_MSforeachdb says:&lt;/p&gt;
&lt;pre&gt;&lt;br /&gt;/*  &lt;br /&gt; * The following table definition will be created by SQLDMO at start of each connection.  &lt;br /&gt; * We don't create it here temporarily because we need it in Exec() or upgrade won't work.  &lt;br /&gt; */  &lt;br /&gt;  &lt;br /&gt;create proc sys.sp_MSforeachdb  &lt;br /&gt; @command1 nvarchar(2000), @replacechar nchar(1) = N'?', @command2 nvarchar(2000) = null, @command3 nvarchar(2000) = null,  &lt;br /&gt; @precommand nvarchar(2000) = null, @postcommand nvarchar(2000) = null  &lt;br /&gt;as  &lt;br /&gt;    set deadlock_priority low  &lt;br /&gt;      &lt;br /&gt; /* This proc returns one or more rows for each accessible db, with each db defaulting to its own result set */  &lt;br /&gt; /* @precommand and @postcommand may be used to force a single result set via a temp table. */  &lt;br /&gt;  &lt;br /&gt; /* Preprocessor won't replace within quotes so have to use str(). */  &lt;br /&gt; declare @inaccessible nvarchar(12), @invalidlogin nvarchar(12), @dbinaccessible nvarchar(12)  &lt;br /&gt; select @inaccessible = ltrim(str(convert(int, 0x03e0), 11))  &lt;br /&gt; select @invalidlogin = ltrim(str(convert(int, 0x40000000), 11))  &lt;br /&gt; select @dbinaccessible = N'0x80000000'  /* SQLDMODbUserProf_InaccessibleDb; the negative number doesn't work in convert() */  &lt;br /&gt;  &lt;br /&gt; if (@precommand is not null)  &lt;br /&gt;  exec(@precommand)  &lt;br /&gt;  &lt;br /&gt; declare @origdb nvarchar(128)  &lt;br /&gt; select @origdb = db_name()  &lt;br /&gt;  &lt;br /&gt; /* If it's a single user db and there's an entry for it in sysprocesses who isn't us, we can't use it. */  &lt;br /&gt;   /* Create the select */  &lt;br /&gt; exec(N'declare hCForEachDatabase cursor global for select name from master.dbo.sysdatabases d ' +  &lt;br /&gt;   N' where (d.status &amp;amp; ' + @inaccessible + N' = 0)' +  &lt;br /&gt;   N' and (DATABASEPROPERTY(d.name, ''issingleuser'') = 0 and (has_dbaccess(d.name) = 1))' )  &lt;br /&gt;  &lt;br /&gt; declare @retval int  &lt;br /&gt; select @retval = @@error  &lt;br /&gt; if (@retval = 0)  &lt;br /&gt;  exec @retval = sys.sp_MSforeach_worker @command1, @replacechar, @command2, @command3, 1  &lt;br /&gt;  &lt;br /&gt; if (@retval = 0 and @postcommand is not null)  &lt;br /&gt;  exec(@postcommand)  &lt;br /&gt;  &lt;br /&gt;   declare @tempdb nvarchar(258)  &lt;br /&gt;   SELECT @tempdb = REPLACE(@origdb, N']', N']]')  &lt;br /&gt;   exec (N'use ' + N'[' + @tempdb + N']')  &lt;br /&gt;  &lt;br /&gt; return @retval  &lt;/pre&gt;
&lt;p&gt; &lt;/p&gt;
&lt;p&gt;See an elaborate explanation of the sp_MSforeachdb stored procedure at &lt;a href="http://www.databasejournal.com/features/mssql/article.php/3441031/SQL-Server-Undocumented-Stored-Procedures-spMSforeachtable-and-spMSforeachdb.htm" target="_blank"&gt;http://www.databasejournal.com/features/mssql/article.php/3441031/SQL-Server-Undocumented-Stored-Procedures-spMSforeachtable-and-spMSforeachdb.htm&lt;/a&gt;&lt;/p&gt;&lt;img src="http://blog.ambitionit.nl/aggbug/27.aspx" width="1" height="1" /&gt;</content>
    </entry>
</feed>
