title: Select query on multiple databases
body: <p>What I am trying to do is verify a URL. I just need to be able to select that single value from all databases that we have currently in SQL Server 2008. All the databases are the same, just multiple instances of the same database for different users.</p>
  
  <p>I am looking to pull one item from one table in each database.</p>
  
  <p>Each database contains a table <code>SETTINGS</code> and within that table a value for <code>MapIconURL</code>. I need that value from each table from within each database. I am looking at around 30 or so databases that would have this value.</p>
  
  <p>So I found the "undocumented" Stored Proc sp_MsForEachDb and have working....to a point.<br>
  The code I am using is this:</p>
  
  <p><code>EXEC sp_MsForEachDb 'use ?; SELECT "?" as databasename,SETTINGSKEYID, SECTION, NAME, INIVALUE, DESCRIPTION
  FROM ?.dbo.SETTINGS
  WHERE [NAME] = "MapIconURL"'</code></p>
  
  <p>I have noticed that it is not selecting all the databases, but that it is also selecting the master table as well as other system tables, and am thinking that may be why it is not selecting all tables.  Is there a way to exclude the system related tables?</p>