如何在SQL Server中使用循环创建多个动态分区。
我有下面的代码,可以一次创建一个分区。
我想使用循环创建多个分区。
请提出建议。
---procedure
CREATE PROCEDURE dynamic_partitions(@FPID AS VARCHAR(10),@model AS NVARCHAR(50),@PNAME AS NVARCHAR(50)) AS
declare @xmla varchar(max) = '
{
"createOrReplace": {
"object": {
"database": "'+@model+'",
"table": "FORECAST_FLASH",
"partition": "'+@PNAME+'_'+@FPID+'"
},
"partition": {
"name": "'+@PNAME+'_'+@FPID+'",
"source": {
"query": "select * from FORECAST_V where fiscal_period_id='+@FPID+'",
"dataSource": "itv_.world"
}
}
}
}
'
EXEC (@xmla) AT SSAS;
----Execution procedure
EXEC [dynamic_partitions] @FPID='2015',@model='TabularProject59',@PNAME='flash';