请考虑以下示例:
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
实际上不存在,我现在InvoiceTable2013
不想创建它,它将在记录 2013 年的第一张发票时自动创建。
任何人都可以帮助我如何在执行之前指定一个条件来验证表的存在UNION ALL
吗?
非常感谢您的帮助。