SSIS 2012 加入 table
SSIS 2012 join table
我需要获取非规范化数据并创建规范化 tables。
我不知道如何获取要插入联接的详细信息 ID table(下例中的 StoreAddress.AddressID)。
如果我在循环中将此作为 T-SQL 中的存储过程执行此操作,我会在将行插入地址后使用@@IDENTITY 来获取密钥,然后使用它插入 StoreAddress。我不知道如何在 SSIS 2012 中使用转换。
以商店和地址为例。
输入数据如下:
Store, Type, Address1, City, State
1, P, 123 Main, Central, PA
1, M, 123 Second, Central, PA
2, P, 123 Third, Pokono, NY
2, M, 123 Third, Pokono, NY
目的地 table 是:
存储(已填充在不同的数据流中)
StoreID, StoreName, StoreNumber
9878, Main street, 1
561, Mountain View, 2
AddressType(已填充在不同的数据流中)
AddressTypeID, Code, Description
1, P, Physical
2, M, Mailing
3, O, Other
地址
AddressID, Addr1, City, State
721, 123 Main, Central, PA
843, 123 Second, Central, PA
1098, 123 Third, Pokono, NY
商店地址
StoreID, AddressID, AddressTypeID
9878, 721, 1
9878, 843, 2
561, 1098, 1
561, 1098, 2
我认为这应该是一个相当常见的转换,并且有一个在 SSIS 中完成它的最佳实践。
感谢您考虑我的问题!
蒂姆
首先插入不同的地址:
INSERT dbo.Address (Addr1, City, State)
SELECT DISTINCT Address1, City, State
FROM input;
(如果您已经有值,可能会有 WHERE NOT EXISTS)
然后使用查找来获取您的 StoreAddress table 的值。
INSERT dbo.StoreAddress (StoreId, AddressId, AddressTypeID)
SELECT
(SELECT s.StoreId from dbo.Store AS s
WHERE s.StoreNumber = i.Store)
, (SELECT a.AddressId FROM dbo.Address AS a
WHERE a.Addr1 = i.Address1
AND a.City = i.City
AND a.State = i.State)
, (SELECT at.AddressTypeId
FROM dbo.AddressType AS at
WHERE at.Code = i.Type)
FROM input AS i;
像这样使用子查询就像使用连接一样,但更安全,因为您不会影响 input
中的行数。
在纯 SSIS 中,执行数据流任务以对您的地址 table 进行排序,仅对地址列使用排序,并打开不同。然后,您可以使用三个查找转换执行另一个数据流任务,以获取 ID,就像我在上面编写的查询中一样。
我需要获取非规范化数据并创建规范化 tables。
我不知道如何获取要插入联接的详细信息 ID table(下例中的 StoreAddress.AddressID)。
如果我在循环中将此作为 T-SQL 中的存储过程执行此操作,我会在将行插入地址后使用@@IDENTITY 来获取密钥,然后使用它插入 StoreAddress。我不知道如何在 SSIS 2012 中使用转换。
以商店和地址为例。
输入数据如下:
Store, Type, Address1, City, State
1, P, 123 Main, Central, PA
1, M, 123 Second, Central, PA
2, P, 123 Third, Pokono, NY
2, M, 123 Third, Pokono, NY
目的地 table 是: 存储(已填充在不同的数据流中)
StoreID, StoreName, StoreNumber
9878, Main street, 1
561, Mountain View, 2
AddressType(已填充在不同的数据流中)
AddressTypeID, Code, Description
1, P, Physical
2, M, Mailing
3, O, Other
地址
AddressID, Addr1, City, State
721, 123 Main, Central, PA
843, 123 Second, Central, PA
1098, 123 Third, Pokono, NY
商店地址
StoreID, AddressID, AddressTypeID
9878, 721, 1
9878, 843, 2
561, 1098, 1
561, 1098, 2
我认为这应该是一个相当常见的转换,并且有一个在 SSIS 中完成它的最佳实践。
感谢您考虑我的问题!
蒂姆
首先插入不同的地址:
INSERT dbo.Address (Addr1, City, State)
SELECT DISTINCT Address1, City, State
FROM input;
(如果您已经有值,可能会有 WHERE NOT EXISTS)
然后使用查找来获取您的 StoreAddress table 的值。
INSERT dbo.StoreAddress (StoreId, AddressId, AddressTypeID)
SELECT
(SELECT s.StoreId from dbo.Store AS s
WHERE s.StoreNumber = i.Store)
, (SELECT a.AddressId FROM dbo.Address AS a
WHERE a.Addr1 = i.Address1
AND a.City = i.City
AND a.State = i.State)
, (SELECT at.AddressTypeId
FROM dbo.AddressType AS at
WHERE at.Code = i.Type)
FROM input AS i;
像这样使用子查询就像使用连接一样,但更安全,因为您不会影响 input
中的行数。
在纯 SSIS 中,执行数据流任务以对您的地址 table 进行排序,仅对地址列使用排序,并打开不同。然后,您可以使用三个查找转换执行另一个数据流任务,以获取 ID,就像我在上面编写的查询中一样。