从存储在变量中的交替登台表名创建动态视图

时间:2015-02-13 08:40:42

标签: ssis

我想像这样动态创建视图:

CREATE VIEW V_Customer
AS SELECT First_Name, Last_Name, Country
FROM CustomerStagingTable1

CREATE VIEW V_Customer
AS SELECT First_Name, Last_Name, Country
FROM CustomerStagingTable2

执行SQL任务'字符串:' CustomerStagingTable1'和' CustomerStagingTable2'应该来自变量。我可以注射'字符串的方式与我为WHERE CLAUSES做的相同:

WHERE A = ?

所以使用:

CREATE VIEW V_Customer
AS SELECT First_Name, Last_Name, Country
FROM ?

1 个答案:

答案 0 :(得分:1)

过去我解决了这个问题

CREATE VIEW V_Customer
AS 

SELECT Source = 1, First_Name, Last_Name, Country
FROM CustomerStagingTable1

UNION ALL

SELECT Source = 2, First_Name, Last_Name, Country
FROM CustomerStagingTable2

GO


SELECT *
FROM V_Customer
WHERE Source = ?