Advertisement
maranite

SSIS Date Fixer

Jun 8th, 2011
252
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.09 KB | None | 0 0
  1. using System;
  2. using System.Data;
  3. using Microsoft.SqlServer.Dts.Pipeline.Wrapper;
  4. using Microsoft.SqlServer.Dts.Runtime.Wrapper;
  5. using Microsoft.SqlServer.Dts.Pipeline;
  6.  
  7. [Microsoft.SqlServer.Dts.Pipeline.SSISScriptComponentEntryPointAttribute]
  8. public class ScriptMain : UserComponent
  9. {
  10.     public override void ProcessInput(int InputID, PipelineBuffer Buffer)
  11.     {
  12.         var indexes = GetColumnIndexes(InputID);
  13.        
  14.         while (Buffer.NextRow())
  15.         {
  16.             foreach (var index in indexes)
  17.             {
  18.                 if (!Buffer.IsNull(index))
  19.                 {
  20.                     var date = Buffer.GetDateTime(index);
  21.                     date = FixYear(date);
  22.                     Buffer.SetDateTime(index, date);
  23.                 }
  24.             }
  25.         }
  26.     }
  27.  
  28.     DateTime FixYear(DateTime input)
  29.     {
  30.         if (input.Year < 50)
  31.             return input.AddYears(2000);
  32.  
  33.         if (input.Year < 100)
  34.             return input.AddYears(1900);
  35.  
  36.         if (input.Year < 300)
  37.             return input.AddYears(1800);
  38.  
  39.         return input;
  40.     }
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement