从存储在变量中的交替暂存 table 名称创建动态视图
create dynamic views from alternating staging table names stored in a variable
我想像这样动态创建视图:
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
在 'Execute SQL Task' 中,其中字符串:'CustomerStagingTable1' 和 'CustomerStagingTable2' 应该来自变量。我可以用与 WHERE CLAUSES:
相同的方式 'inject' 字符串吗
WHERE A = ?
所以使用:
CREATE VIEW V_Customer
AS SELECT First_Name, Last_Name, Country
FROM ?
以前我是这样解决的
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 = ?
我想像这样动态创建视图:
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
在 'Execute SQL Task' 中,其中字符串:'CustomerStagingTable1' 和 'CustomerStagingTable2' 应该来自变量。我可以用与 WHERE CLAUSES:
相同的方式 'inject' 字符串吗WHERE A = ?
所以使用:
CREATE VIEW V_Customer
AS SELECT First_Name, Last_Name, Country
FROM ?
以前我是这样解决的
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 = ?