﻿<?xml version='1.0' encoding='UTF-8'?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/"><channel><title>SQLServerCentral / Integration Services / Data Warehousing  / Merge,Look Up,SCD which one is good for millions of records / Latest Posts</title><generator>InstantForum.NET v2.9.0</generator><description>SQLServerCentral</description><link>http://www.sqlservercentral.com/Forums/</link><webMaster>notifications@sqlservercentral.com</webMaster><lastBuildDate>Tue, 21 May 2013 19:40:29 GMT</lastBuildDate><ttl>20</ttl><item><title>RE: Merge,Look Up,SCD which one is good for millions of records</title><link>http://www.sqlservercentral.com/Forums/Topic1429268-364-1.aspx</link><description>Hi Rocky´sI totally agree with that, the use of the merge command is for me the better option. I designed several ETL packages the last year and I tried the 3 options, and at the end I always used the Merge command.Here I leave you a code snippet from my personal library. This code makes the following:- Log the start time and name of the package in a custom log table with an identity column- Merge into a target table the results of a query (as a source). You can adapt the source query to your needs- The columns that match the merge condition are updated, if not, they are inserted.- At the end the finish time is log together with the row count of updated and inserted records.[code="sql"]-- I use a table to log the start and finish time, package name, number of rows inserted and number of rows updatedinsert into SSIS_Log (PackageName,DTStart) values (?,GetDate()); -- Map the System variable "PackageName"declare         @mergeResultsTable table (MergeAction VARCHAR(20));  declare         @insertCount int,         @updateCount int;MERGE Table_A AS TARGETUSING (SELECT		 Col1	,Col2	.....	,ColNFROM	Table_B) AS SOURCE ON (TARGET.Key1 = SOURCE.Key1 and TARGET.Key_2 = SOURCE.Key_2)-- UpdateWHEN MATCHED THEN UPDATE SET       TARGET.Col1= SOURCE.Col1      ,TARGET.Col2= SOURCE.Col2	  ,TARGET.UpdateDT=GetDate() -- I create a UpdateDT column in the target table to store the update datetime	  -- etc--InsertWHEN NOT MATCHED BY TARGET THEN INSERT(       Col1      ,Col2	  ,CreateDT -- I create a CreateDT column in the target table to store the insert (or creation) datetime	  -- etc)VALUES(	   SOURCE.Col1	  ,SOURCE.Col2	  ,GetDate()	  -- etc)OUTPUT $action into @mergeResultsTable;  update SSIS_Logset UpdatedCount =        -- Log the count of updated rows(SELECT COUNT(*)  FROM @mergeResultsTable WHERE MergeAction = 'UPDATE'), InsertedCount =         -- Log the count of inserted rows(SELECT COUNT(*)  FROM @mergeResultsTable WHERE MergeAction = 'INSERT'),DTFinish = GetDate()where Idx = (  select MAX(Idx)  from SSIS_Log );[/code]If your target table should be treated as a SCD I strongly recommend to you the following article by Adam Aspin:[url=http://www.sqlservercentral.com/articles/MERGE/73805/]Slowly changing dimensions using T-SQL MERGE[/url]If you have further question just write me.Kind Regards</description><pubDate>Tue, 12 Mar 2013 03:04:40 GMT</pubDate><dc:creator>Paul Hernández</dc:creator></item><item><title>RE: Merge,Look Up,SCD which one is good for millions of records</title><link>http://www.sqlservercentral.com/Forums/Topic1429268-364-1.aspx</link><description>Use the Merge, of those 3.</description><pubDate>Mon, 11 Mar 2013 15:12:42 GMT</pubDate><dc:creator>tmitchelar</dc:creator></item><item><title>Merge,Look Up,SCD which one is good for millions of records</title><link>http://www.sqlservercentral.com/Forums/Topic1429268-364-1.aspx</link><description>Hi,I am new to SSIS.I have to load 50 millions of records(full load) into a SQL Server table.After the full load I have to create another package for incremental load based on Hash value.Please suggest me one of the below mentioned approach to get good performance.-Merge command-Look Up-SCDThanks in advance</description><pubDate>Mon, 11 Mar 2013 07:41:33 GMT</pubDate><dc:creator>Rocky's</dc:creator></item></channel></rss>