title: Database cannot be opened because it is offline. But it is excluded allready in select..
body: <p>I get this error:
  Msg 942, Level 14, State 4, Line 2
  Database 'TESTNA' cannot be opened because it is offline.</p>
  
  <pre><code>select name 
  from sys.databases 
  where state = 0  -- exclude offline databases
      and name &lt;&gt; db_name() -- exclude current dataase
      and OBJECT_ID (name+'.dbo.some_table','U') is not null  -- returns all   databases with some_table
  </code></pre>
  
  <p>I don't get it. Why this error? Database TESTNA is excluded with "state=0" condition. </p>