简体   繁体   English

SSIS 查找转换不捕获不匹配的值

[英]SSIS Lookup transformation not capturing non matching values

I'm using the lookup transformation to look back at my data warehouse table to find any deleted records from production and then send them to a staging table to be removed from the datawarehouse table.我正在使用查找转换来回顾我的数据仓库表,以查找生产中任何已删除的记录,然后将它们发送到要从数据仓库表中删除的暂存表。

Logically, if a record is removed in the production table and exists in the datawarehouse table this lookup should find it and redirect it to No Match Output correct?从逻辑上讲,如果在生产表中删除了一条记录并存在于数据仓库表中,则此查找应该找到它并将其重定向到“ No Match Output是否正确?

The issue is the lookup isn't finding the non-matching records or I'm doing something backwards.问题是查找没有找到不匹配的记录,或者我在做一些倒退的事情。

I should add that in production there are 4 identical databases for four different regions.我应该补充一点,在生产中,四个不同区域有 4 个相同的数据库。 My package loops through each one by looping through the connection strings in a config file.我的包通过循环遍历配置文件中的连接字符串来遍历每个包。 Then all of these records are marked with which database they came from and added to the datawarehouse table.然后所有这些记录都用它们来自哪个数据库进行标记并添加到数据仓库表中。

This is the part inside my data flow task that isn't working properly:这是我的数据流任务中无法正常工作的部分:

在此处输入图片说明

Inside the "Fact Table" OLE DB source I'm pulling the records from my fact table where the Region equals whichever region the connection string identifies by using numbers 1 - 4. I put the query in a variable so that it can be dynamic.在“事实表”OLE DB 源中,我从事实表中提取记录,其中Region等于连接字符串使用数字 1 - 4 标识的任何区域。我将查询放在一个变量中,以便它可以是动态的。 I'm also only pulling the columns that cannot be null inside the staging table in order to minimize the amount I'm pulling and I only really need the ID and Region column to delete the records because they should be unique within their respective regions.我也只能拉不能是临时表内空列,以尽量减少我拉量,我只真正需要的ID和地区列删除记录,因为他们应该是各自区域内是唯一的。

Inside FindDeletes variable:FindDeletes变量中:

"SELECT ID ,
        ParentItemID ,
        IsTransPerPiece ,
        PerPieceCostQuantity ,
        PerPieceCost ,
        PerPieceUnitCost ,
        OriginalPerPieceCostQuantity ,
        OriginalTransFee ,
        TransFee ,
        CostTrans ,
        CostLabor ,
        OriginalCostQuantity ,
        OriginalFacilityFees ,
        FacilityFees ,
        Region ,
        HashValue ,
        CreateDate 
FROM dbo.FactInvoiceWasteManifests
WHERE Region = CASE " + (DT_WSTR, 2) @[User::ConnectionStringID] +
       " WHEN 1 THEN 'NE'
        WHEN 2 THEN 'BALT'
        WHEN 3 THEN 'NY' 
        WHEN 4 THEN 'PA'
        END "

Inside OLE DB Source showing the variable query:在 OLE DB 源中显示变量查询:

在此处输入图片说明

Next we go into the transformation in which I redirect rows that don't match to the No Match Output接下来我们进入转换,在该转换中我重定向与No Match Output不匹配的行

在此处输入图片说明

The connection here is to production and the query here is again dynamic because the Region column doesn't exist in production.这里的连接是到生产,这里的查询又是动态的,因为生产中不存在Region列。

在此处输入图片说明

Showing the expression for the lookup SQL query:显示查找 SQL 查询的表达式:

在此处输入图片说明

"SELECT  ID,
        CASE " + (DT_WSTR, 2) @[User::ConnectionStringID] +
       " WHEN 1 THEN CAST('NE' AS NVARCHAR(25))
        WHEN 2 THEN CAST('BALT' AS NVARCHAR(25))
        WHEN 3 THEN CAST('NY' AS NVARCHAR(25))
        WHEN 4 THEN CAST('PA' AS NVARCHAR(25))
        END AS Region 
FROM    dbo.InvoiceWasteManifests;"

UPDATED QUERY:更新的查询:

"SELECT  ID,
        CASE 
        WHEN " + (DT_WSTR, 2) @[User::ConnectionStringID] + "=1 THEN CAST('NE' AS NVARCHAR(25))
        WHEN " + (DT_WSTR, 2) @[User::ConnectionStringID] + "=2 THEN CAST('BALT' AS NVARCHAR(25))
        WHEN " + (DT_WSTR, 2) @[User::ConnectionStringID] + "=3 THEN CAST('NY' AS NVARCHAR(25))
        WHEN " + (DT_WSTR, 2) @[User::ConnectionStringID] + "=4 THEN CAST('PA' AS NVARCHAR(25))
        END AS Region 
FROM    dbo.InvoiceWasteManifests;"

在此处输入图片说明

Lastly, I join the two tables on Region and then search on ID.最后,我在Region上连接两个表,然后搜索 ID。 The result is nothing happens and no records are redirected anywhere.结果是什么也没有发生,也没有记录被重定向到任何地方。

It turns out I didn't fully understand how the Lookup Transformation works.结果我没有完全理解查找转换是如何工作的。 I solved my problem this morning by also using the ID column as a join instead of caching it.我今天早上通过使用ID列作为连接而不是缓存它来解决我的问题。

在此处输入图片说明

This is the first dynamic query you need to put:这是您需要放置的第一个动态查询:

  --declare @sql varchar(max)
  --declare @ConnectionStringID varchar(50) =1
    set @sql = 
    'SELECT ID ,
            ParentItemID ,
            IsTransPerPiece ,
            PerPieceCostQuantity ,
            PerPieceCost ,
            PerPieceUnitCost ,
            OriginalPerPieceCostQuantity ,
            OriginalTransFee ,
            TransFee ,
            CostTrans ,
            CostLabor ,
            OriginalCostQuantity ,
            OriginalFacilityFees ,
            FacilityFees ,
            Region ,
            HashValue ,
            CreateDate 
    FROM dbo.FactInvoiceWasteManifests
    WHERE Region = CASE 
            WHEN ' +  @ConnectionStringID + '=1 THEN ''''''''+CAST(''NE'' AS NVARCHAR(25))+''''''''
            WHEN ' + @ConnectionStringID + '=2 THEN ''''''''+CAST(''BALT'' AS NVARCHAR(25))+''''''''
            WHEN ' +  @ConnectionStringID + '=3 THEN ''''''''+CAST(''NY'' AS NVARCHAR(25))+''''''''
            WHEN ' + @ConnectionStringID + '=4 THEN ''''''''+CAST(''PA'' AS NVARCHAR(25))+''''''''
            END' 
  --print (@Sql)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM