由于目标表

时间:2017-08-17 18:43:55

标签: ssis

我正在开发SSIS包,仅在QA环境中获取以下错误,而不是Dev环境。不知道为什么我收到错误说有架构更改。是因为存储过程结束时截断表语句。我通过QA中的SQL作业运行SSIS包。如果截断是问题,他们为什么不在Dev中出现问题?

  

SSIS错误代码DTS_E_OLEDBERROR。发生OLE DB错误。错误代码:0x80004005。
  OLE DB记录可用。来源:“Microsoft SQL Server Native Client 10.0”Hresult:0x80004005描述:“由于目标表的架构更改,插入批量失败。”。

     

SSIS错误代码DTS_E_INDUCEDTRANSFORMFAILUREONERROR。 “输入”OLE DB目标输入“(29)”失败,因为发生错误代码0xC020907B,并且“输入”OLE DB目标输入“(29)”上的错误行处置指定错误失败。指定组件的指定对象发生错误。在此之前可能会发布错误消息,其中包含有关失败的更多信息。

我的存储过程如下:

SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

CREATE PROCEDURE [dbo].[getPartiesPremiumFinancials_SSIS]
/* pulls the information relating to the income statement, 
balance sheet and cash flow statement, including total employees
converts the historical data at the most recent spot rate*/
    @dataItemstring VARCHAR(MAX) = '2,7,21,15,28,34,75,97,208,373,400,1002,1004,1007,1008,1009,1012,1014,1018,1021,1043,1054,1085,1222,1275,1276,1310,1312,2004,2005,2006,2021,2055,2056,3058,3069,3523,4051,4173,4371,4377,35379,2021',
    @periodtypeId INT = 4
AS
BEGIN
    SET NOCOUNT ON;
    DECLARE @date DATE = '2016-01-01'

    IF EXISTS(SELECT * FROM sys.indexes 
              WHERE object_id = object_id('dataItemId') AND NAME = 'idx_dataItemId')
        DROP INDEX idx_dataItemId ON dataItemId

    IF EXISTS(SELECT * FROM sys.indexes 
              WHERE object_id = object_id('tempCompany') AND NAME = 'idx_tempCompany')
        DROP INDEX idx_tempCompany ON tempCompany

    IF EXISTS(SELECT * FROM sys.indexes 
              WHERE object_id = object_id('EstPeriodTbl') AND NAME ='idx_EstPeriodTbl')
        DROP INDEX idx_EstPeriodTbl ON EstPeriodTbl

    IF EXISTS(SELECT * FROM sys.indexes 
              WHERE object_id = object_id('maxDate') AND NAME ='idx_maxDate')
        DROP INDEX idx_maxDate ON maxDate

    IF EXISTS(SELECT * FROM sys.indexes 
              WHERE object_id = object_id('currencyTbl') AND NAME = 'idx_currencyTbl')
        DROP INDEX idx_currencyTbl ON currencyTbl

    IF EXISTS(SELECT * FROM sys.indexes 
              WHERE object_id = object_id('temp1') AND NAME ='idx_temp1')
        DROP INDEX idx_temp1 ON temp1

    IF EXISTS(SELECT * FROM sys.indexes 
              WHERE object_id = object_id('PartiesPremiumFinancials') 
                AND NAME ='ix_PartiesPremiumFinancials_companyId')
    DROP INDEX ix_PartiesPremiumFinancials_companyId ON PartiesPremiumFinancials

    INSERT INTO dataItemId
        SELECT * 
        FROM dbo.splitstring(@dataItemstring)

    CREATE NONCLUSTERED INDEX idx_dataItemId ON dataItemId(val)


    INSERT INTO tempCompany 
        SELECT
            fp.companyId, fp.fiscalYear, fp.fiscalQuarter,
            fi.financialperiodid, fi.periodEndDate,
            fc.currencyId, fp.periodtypeid, 
            ROW_NUMBER() OVER (PARTITION BY fp.companyId, fp.fiscalYear, fp.fiscalQuarter ORDER BY fi.periodEndDate DESC) rowno 
        FROM
            ciqFinPeriod fp
        INNER JOIN 
            ciqcompany c ON c.companyId = fp.companyId
        JOIN 
            ciqFinInstance fi ON fi.financialperiodid = fp.financialperiodid
        JOIN
            ciqFinInstanceToCollection ic ON ic.financialInstanceId = fi.financialInstanceId
        LEFT JOIN
            ciqFinCollection fc ON fc.financialCollectionId = ic.financialCollectionId
        LEFT JOIN
            ciqFinCollectionData fd ON fd.financialCollectionId = fc.financialCollectionId
        WHERE
            fp.periodTypeId = @periodtypeId
            AND fi.periodenddate >= @date

    CREATE NONCLUSTERED INDEX idx_tempCompany ON tempCompany(rowno)


    INSERT INTO EstPeriodTbl 
        SELECT
            companyId, fiscalYear, fiscalQuarter,
            financialPeriodId, periodenddate, currencyId,
            periodtypeid, rowno
        FROM
            tempCompany a
        WHERE
            a.rowno = 1
        ORDER BY
            companyid, periodenddate

    /* finds the max pricing date for each table */
    CREATE NONCLUSTERED INDEX idx_EstPeriodTbl ON EstPeriodTbl(companyId, periodenddate, fiscalYear, fiscalQuarter, currencyId, financialPeriodId, rowno)  

    INSERT INTO maxDate
        SELECT
            MAX(exr.pricingDate) AS pricingDate, 
            exr.currencyId
        FROM
            ciqExchangeRate exr
        INNER JOIN
            EstPeriodTbl ept ON ept.currencyId = exr.currencyId
        GROUP BY
            exr.currencyId

    CREATE NONCLUSTERED INDEX idx_maxDate ON maxDate(pricingDate, currencyId)  


    INSERT INTO currencyTbl 
        SELECT 
            a.currencyId, b.pricingDate, a.CurrencyRateClose
        FROM
            ciqExchangeRate a
        INNER JOIN
            maxDate b ON a.currencyId = b.currencyId 
                      AND a.pricingDate = b.pricingDate
        ORDER BY 
            currencyID

    CREATE NONCLUSTERED INDEX idx_currencyTbl 
        ON currencyTbl(currencyId, pricingDate, CurrencyRateClose)  

    /* combine the tables and convert into USD using the most recent pricing date, if a goforward estimate*/


    INSERT INTO temp1 
        SELECT
            a.companyId,
            fd.dataItemId,
            di.dataItemName,
            dataItemvalue = CASE WHEN fd.unitTypeId = 0 
                                    THEN fd.dataitemvalue
                                 WHEN fd.unitTypeId = 1 
                                    THEN fd.dataitemvalue * 1e3 
                                 ELSE fd.dataitemvalue * 1e6 
                            END,
            a.fiscalYear, a.fiscalQuarter, a.periodenddate,
            fc.currencyId, a.periodTypeId
        FROM
            EstPeriodTbl a
        JOIN
            ciqFinInstance fi ON fi.financialPeriodId = a.financialPeriodId
        JOIN
            ciqFinInstanceToCollection ic ON ic.financialInstanceId = fi.financialInstanceId
        INNER JOIN
            ciqFinCollection fc ON fc.financialCollectionId = ic.financialCollectionId
        INNER JOIN
            ciqFinCollectionData fd ON fd.financialCollectionId = fc.financialCollectionId
        INNER JOIN
            dataItemId d ON d.val = fd.dataItemId
        INNER JOIN
            ciqDataItem di ON di.dataItemId = fd.dataItemId
        --join #currencyTbl ex on (ex.currencyId = a.currencyId)
        WHERE
            --fd.dataitemid in (select val from @dataitemid)
            fi.latestForFinancialPeriodFlag = 1 -- flag indicating that this instance is the latest one for the financial period
            AND fi.latestFilingforInstanceFlag = 1 -- flag considers any restatements
        ORDER BY
            a.companyId DESC, dataitemid ASC, a.fiscalYear DESC, a.fiscalQuarter DESC

    CREATE NONCLUSTERED INDEX idx_temp1 
        ON temp1 (companyId, dataItemId, fiscalYear, fiscalQuarter, currencyId)  

    SELECT
        a.companyId,
        a.dataItemId, a.dataItemName,
        dataItemvalueUSD = CASE WHEN conv.currencyConversionFlag  = 1 
                                   THEN a.dataItemValue / ex.currencyRateClose 
                                   ELSE a.dataItemValue 
                           END, 
        a.fiscalYear, a.fiscalQuarter,
        a.currencyId, a.periodEndDate, a.periodTypeId 
    FROM
        temp1 a
    JOIN
        currencyTbl ex ON ex.currencyId = a.currencyId
    INNER JOIN
        ciqDataItemConversionRule conv ON conv.dataItemId = a.dataItemId
    ORDER BY
        a.companyId DESC, a.dataitemid ASC, a.fiscalYear DESC, a.fiscalQuarter DESC


    truncate table [dbo].[dataItemId];
    truncate table [dbo].[tempCompany];
    truncate table [dbo].[EstPeriodTbl];
    truncate table [dbo].[maxDate];
    truncate table [dbo].[currencyTbl];
    truncate table [dbo].[temp1];

    CREATE NONCLUSTERED INDEX ix_PartiesPremiumFinancials_companyId 
        ON CoreReferenceStaging.dbo.PartiesPremiumFinancials (companyId, dataItemId, dataItemName, dataItemvalueUSD, fiscalYear, fiscalQuarter, currencyId, periodEndDate, periodtypeId) 
END

0 个答案:

没有答案