title: Union all if the table exists in SQL server 2008
body: <p>In the below code, I need to check if the table exists in each line. Please tell me how to do it.</p>
  
  <pre><code>Select * from Table 1 union all
  select * from Table 2 union all
  Select * from Table 3
  </code></pre>
  
  <p>I tried this but didn't work</p>
  
  <pre><code>if objectid ('Table1') is not null
  Select * from Table 1 union all
  if objectid ('Table2') is not null
  select * from Table 2 union all
  if objectid ('Table3') is not null
  Select * from Table 3
  </code></pre>