title: CREATE VIEW in SQL Server using UNION ALL
body: <p>Please consider the below example:</p>
  
  <pre><code>CREATE VIEW VW_YearlySales
  AS
  
  SELECT 2011 AS YearNo, ProductID, SUM(Amount) FROM InvoiceTable2011
  UNION ALL
  SELECT 2012 AS YearNo, ProductID, SUM(Amount) FROM InvoiceTable2012
  UNION ALL
  SELECT 2013 AS YearNo, ProductID, SUM(Amount) FROM InvoiceTable2013
  
  GO
  </code></pre>
  
  <p>The <code>InvoiceTable2013</code> doesn't exist actually and I don't want to create it right now, it will be created automatically when recording the first invoice for year 2013.</p>
  
  <p>Can anyone help me on how to specify a condition that will verify the existence of the table before doing the <code>UNION ALL</code>?</p>
  
  <p>Many thanks for your help.</p>