在 Azure Synapse Analytics 中以 XML 的形式执行脚本

Executing scripts as XML in Azure Synapse Analytics

我无法通过将脚本解析为 XML 来执行脚本,如 here 所述。我看到基于 MSDN 的 Synapse 不支持它。有人可以帮助我如何在 SQL DW 中实现这一目标吗?我有一个包含所有 SQL 语句的 table,我想通过循环遍历该列中的每条记录来执行它们。

DDL:

CREATE TABLE [#Temp]
(
JOB_ID INT NOT NULL,
SQL_STMNT NVARCHAR(2000)
);

DML:

INSERT INTO #Temp
SELECT 100, 'SELECT * FROM Table_A WHERE MyDate = @ProcessDate'
UNION 
SELECT 103, 'SELECT * FROM Table_B WHERE MyDate = @ProcessDate AND MyCode = ''ABC'''
UNION 
SELECT 110, 'SELECT * FROM Table_C WHERE MyDate = @ProcessDate AND MyID = 345'
UNION 
SELECT 200, 'SELECT * FROM Table_D WHERE MyDate = @ProcessDate'
UNION 
SELECT 230, 'SELECT * FROM Table_E WHERE MyDate = @ProcessDate'

您可以使用 STRING_AGG function:

DECLARE @sql nvarchar(max) = (
 SELECT STRING_AGG(CAST(SQL_STMNT as nvarchar(max)), '; ') WITHIN GROUP (ORDER BY JOB_ID ASC)
 FROM #Temp
);
exec(@sql);