如何仅在使用SSIS时将插入应用于表以获取新记录?

时间:2014-02-26 06:08:42

标签: sql-server ssis

我有这个插入脚本只插入新记录。但我意识到如果我将整个脚本放在OLE DB源中。它会产生一个错误,因为它就像我在不存在的地方声明目标表一样(从SMEC_DW.dbo.DimCustomerContact中选择*)

我应该为此使用SCD(缓慢变化的尺寸)吗?或者是否有一个控制流项目,我可以用它来应用我在下面的插入查询。

INITIAL插入DimCustomerContact表

INSERT  INTO BLANK_DW.dbo.DimCustomerContact
        (
          CustomerContactInt ,
          ContactID ,
          SiteID ,
          ClientName ,
          ContactFirstName ,
          ContactLastName ,
          Position ,
          Phone ,
          MobilePhone ,
          EmailAddress ,
          CustomerBaseID ,
          RecordSource ,
          RecordType ,
          SiteURN ,
          SiteDesc ,
          CustomerLink ,
          HomeCurrencyCode ,
          CustomerID ,
          CustomerCurrencyCode ,
          CustomerName ,
          CustomerShortName ,
          Address ,
          City ,
          PostalCode ,
          CountryCode ,
          CountryName ,
          StateCode ,
          StateName ,
          CustomerPhone ,
          Fax ,
          TaxCode ,
          ProspectID ,
          CreateDate ,
          LastUpdateDate ,
          MasterCustomerID ,
          MasterCustomerName ,
          MasterCustomerNotes
        )
        SELECT  *
        FROM    BLANK_ODS.dbo.ODSCustomerContact a
                JOIN BLANK_ODS.dbo.ODSCustomerBase b ON a.ClientName = b.CustomerName
                LEFT OUTER JOIN BLANK_ODS.dbo.ODSMasterCustomer c ON b.CustomerName = c.MasterCustomerName

仅在新记录中插入DimCustomerContact中的数据

INSERT  INTO BLANK_DW.dbo.DimCustomerContact
    (
      CustomerContactInt ,
      ContactID ,
      SiteID ,
      ClientName ,
      ContactFirstName ,
      ContactLastName ,
      Position ,
      Phone ,
      MobilePhone ,
      EmailAddress ,
      CustomerBaseID ,
      RecordSource ,
      RecordType ,
      SiteURN ,
      SiteDesc ,
      CustomerLink ,
      HomeCurrencyCode ,
      CustomerID ,
      CustomerCurrencyCode ,
      CustomerName ,
      CustomerShortName ,
      Address ,
      City ,
      PostalCode ,
      CountryCode ,
      CountryName ,
      StateCode ,
      StateName ,
      CustomerPhone ,
      Fax ,
      TaxCode ,
      ProspectID ,
      CreateDate ,
      LastUpdateDate ,
      MasterCustomerID ,
      MasterCustomerName ,
      MasterCustomerNotes
    )
    SELECT  *
    FROM    BLANK_ODS.dbo.ODSCustomerContact a
            JOIN BLANK_ODS.dbo.ODSCustomerBase b ON a.ClientName = b.CustomerName
            LEFT OUTER JOIN BLANK_ODS.dbo.ODSMasterCustomer c ON b.CustomerName = c.MasterCustomerName
    WHERE   NOT EXISTS ( SELECT *
                         FROM   BLANK_DW.dbo.DimCustomerContact )

我的目标是仅使用SSIS插入新记录。我应该使用什么控制流程项目?

这是我在sql命令文本下放置脚本后在OLE DB Source中使用预览按钮时出现的错误

enter image description here

我可以将整个命令放在单个执行SQL任务中或使用SCD吗?是的,那是怎么回事?

1 个答案:

答案 0 :(得分:1)

您的INSERT / SELECT语句需要进入Execute SQL任务,而不是进入数据流。它没有返回记录。事实上,它甚至不需要进入SSIS,它可以进入SQL代理作业内的执行SQL步骤。