如何在ssis包中将数据从源表复制到目标表时更新现有记录

时间:2016-09-18 10:17:50

标签: sql tsql ssis sql-server-2012

MERGE INTO cms_universal_metadata AS Target
USING cms_universal_metadata_stage AS Source
ON Target.asset_folder_hash =Source.stg_asset_folder_hash
-- AND Target.Mid =Source.Mid 
WHEN MATCHED THEN 
UPDATE SET Target.asset_folder_path = Source.stg_asset_folder_path ,
Target.a_archive = Source.stg_a_archive,
Target.acl_name = Source.stg_acl_name
WHEN NOT MATCHED BY Target THEN
INSERT (asset_folder_path,a_archive,acl_name)
VALUES (Source.stg_asset_folder_path,Source.stg_a_archive,Source.stg_a_archive);

我有一个自动化ssis包,需要从登台表复制到目标表。如果再次从登台复制到目的地那个时候如果有相同的记录那么它应该更新,否则它将是insert.please任何人帮助我吗?

2 个答案:

答案 0 :(得分:0)

尝试使用Lookup transformation转换OLEDB command来更新现有记录。

了解:

慢慢改变尺寸 - https://msdn.microsoft.com/en-us/library/ms141715.aspx

T-SQL MERGE - https://msdn.microsoft.com/en-us/library/bb510625.aspx

答案 1 :(得分:0)

您搜索的内容称为Upsert网络中有许多tuto链接,因为贝尔必须帮助您:

SSIS Upsert With Lookup Transform

Upsert and Merge with SSIS