title: SQL Server 2014-Run SQL merge statement in loop/batches for 80M rows
body: <p>Need some help in query optimization for below merge statement. This query takes max time during execution of our process because of number of rows and merge does operation in one shot.
  I would like to modify it little bit so I can run it in loop or batch process.</p>
  
  <pre><code>    MERGE Target_DB.[dbo].[target_tbl] A
      USING   Source_DB].[DBO].[source_tbl] B
      INNER JOIN (SELECT DISTINCT [IndividualEligibility_IDNO],[Case_NUMB],[MCI_NUMB],[Program_CODE],[Subprogram_CODE],[AGSequence_NUMB],[CategorySequence_NUMB] 
  FROM staging_tbl  
  where [IndividualEligibility_IDNO] is not null) C
  ON C.[Case_NUMB] = B.[CASE_NUM] AND B.[PROGRAM_CD]= C.[Program_CODE] AND B.[SUBPROGRAM_CD]=  C.[Subprogram_CODE] AND B.[AG_SEQ_NUM]= C.[AGSequence_NUMB]AND C.[CategorySequence_NUMB]= B.[CAG_ELIG_SEQ_NUM]AND C.[MCI_NUMB] = B.[MCI_NUM] 
  ON (A.[IndividualEligibility_IDNO] = C.[IndividualEligibility_IDNO])
  WHEN MATCHED THEN  
  UPDATE
  SET 
  WHEN NOT MATCHED THEN
  INSERT
  (
  )
  VALUES
  (
  );
  </code></pre>