CREATE VIEW in MSSQL Server using UNION ALL
===

Please consider the below example:


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

The InvoiceTable2013 does 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.

Can anyone help me on how to specify a condition that will verify the existence of the table before doing the UNION ALL?

Many thanks for your help.
