Так что ниже не работает при запуске.Я добавил столбец [Target_Id] INT
в мое заявление Create Table
.Теперь выдает ошибку:
Сообщение 213, уровень 16, состояние 1, строка 1376
Имя столбца или количество предоставленных значений не соответствует определению таблицы.
Вот и вся партия:
--FactSite
IF OBJECT_ID('tempdb..#factSite', 'U') IS NOT NULL
DROP TABLE #factSite;
CREATE TABLE #factSite
(
[ID] INT,
[Target_Id] INT,
[SYS_CHANGE_OPERATION] NVARCHAR(1),
DimSite_Id INT,
DimSubSite_Id INT,
DimSubParameters_Id INT
);
WITH cteUpivotFactSite AS
(
SELECT [ID], [SYS_CHANGE_OPERATION], [SiteID], [SubSiteID],
[SubParameterVal] AS [SubParameter]
FROM Staging.AppsFlyerBasic
CROSS APPLY (
VALUES ('SubParam1',[SubParam1]),
('SubParam2',[SubParam2]),
('SubParam3',[SubParam3]),
('SubParam4',[SubParam4]),
('SubParam5',[SubParam5])
) x ([DimensionVal],[SubParameterVal])
)
INSERT INTO #factSite
SELECT src.[ID], NULL, src.[SYS_CHANGE_OPERATION],
site.[ID] AS DimSite_Id, subSite.ID AS DimSubSite_Id,
subParameters.[ID] AS DimParameters_Id
FROM cteUpivotFactSite AS src
INNER JOIN AppsFlyer.DimSite AS site
ON (src.[SiteID] = site.[Name] OR (src.[SiteID] IS NULL AND site.[Name] IS NULL))
INNER JOIN AppsFlyer.DimSubSite AS subSite
ON (src.[SubSiteID] = subSite.[Name] OR (src.[SubSiteID] IS NULL AND subSite.[Name] IS NULL))
INNER JOIN AppsFlyer.DimSubParameters AS subParameters
ON (src.[SubParameter] = subParameters.[Name] OR (src.[SubParameter] IS NULL AND subParameters.[Name] IS NULL))
Но если я разделю партию на две части, это сработает.
Пакет 1:
--FactSite
IF OBJECT_ID('tempdb..#factSite', 'U') IS NOT NULL
DROP TABLE #factSite;
CREATE TABLE #factSite
(
[ID] INT,
[Target_Id] INT,
[SYS_CHANGE_OPERATION] NVARCHAR(1),
DimSite_Id INT,
DimSubSite_Id INT,
DimSubParameters_Id INT
);
Пакет 2:
WITH cteUpivotFactSite AS
(
SELECT [ID], [SYS_CHANGE_OPERATION], [SiteID], [SubSiteID],
[SubParameterVal] AS [SubParameter]
FROM Staging.AppsFlyerBasic
CROSS APPLY (
VALUES ('SubParam1',[SubParam1]),
('SubParam2',[SubParam2]),
('SubParam3',[SubParam3]),
('SubParam4',[SubParam4]),
('SubParam5',[SubParam5])
) x ([DimensionVal],[SubParameterVal])
)
INSERT INTO #factSite
SELECT src.[ID], NULL, src.[SYS_CHANGE_OPERATION],
site.[ID] AS DimSite_Id, subSite.ID AS DimSubSite_Id,
subParameters.[ID] AS DimParameters_Id
FROM cteUpivotFactSite AS src
INNER JOIN AppsFlyer.DimSite AS site
ON (src.[SiteID] = site.[Name] OR (src.[SiteID] IS NULL AND site.[Name] IS NULL))
INNER JOIN AppsFlyer.DimSubSite AS subSite
ON (src.[SubSiteID] = subSite.[Name] OR (src.[SubSiteID] IS NULL AND subSite.[Name] IS NULL))
INNER JOIN AppsFlyer.DimSubParameters AS subParameters
ON (src.[SubParameter] = subParameters.[Name] OR (src.[SubParameter] IS NULL AND subParameters.[Name] IS NULL))
Кто-нибудь знает, почему один пакет не может удалить и создать временную таблицу, но две отдельные партии работают