Question

TableOne.txt (txt file)

LoadNumber  Name    Address
101         Yogesh  ABC
102         Zebra   XYZ
103         Kattle  BTM

TableTwo.txt (txt file)

LoadNumber  Cost    EName
101         240     Yogesh
105         500     Kavita
110         340     Kamal

Now I want to compare these flat files. 1. I want to all data which is not present in table two text file base is LoadNumber and also I want all data which is not present in table one text files base is LoadNumber

Was it helpful?

Solution

1- read both text files through a Flat File Source component

2- Sort them by LoadNumber

3- connect to a Merge Join compnonent (join type: full outer join) and join by TableOne.LoadNumber - TableTwo.LoadNumber

4- Conditional Split based on ISNULL(tableXXXX.LoadNumber), e.g. if null for TableOne.LoadNumber then is missing from table1

enter image description here

OTHER TIPS

you can do that a C# script in a SSIS script task. Ref: http://www.java2s.com/Code/CSharp/File-Stream/Comparetwofiles.htm

using System; 
using System.IO;  

public class CompFiles {  
  public static void Main(string[] args) {  
    int i=0, j=0;  
    FileStream f1;  
    FileStream f2;  

    try {  
      // open first file 
      try {  
        f1 = new FileStream(args[0], FileMode.Open);  
      } catch(FileNotFoundException exc) {  
        Console.WriteLine(exc.Message);  
        return;  
      }  

      // open second file  
      try {  
        f2 = new FileStream(args[1], FileMode.Open);  
      } catch(FileNotFoundException exc) {  
        Console.WriteLine(exc.Message);  
        return;  
      }  
    } catch(IndexOutOfRangeException exc) {  
      Console.WriteLine(exc.Message + "\nUsage: CompFile f1 f2");  
      return;  
    }  

    // Compare files  
    try {  
      do {  
        i = f1.ReadByte();  
        j = f2.ReadByte();  
        if(i != j) break; 
      } while(i != -1 && j != -1);  
    } catch(IOException exc) {  
      Console.WriteLine(exc.Message);  
    }  
    if(i != j)  
      Console.WriteLine("Files differ."); 
    else 
      Console.WriteLine("Files are the same."); 

    f1.Close();  
    f2.Close();  
  }  
}

Another method could be to load both flat files into SQL tables ins Flat File Source & use Execute SQL tasks to JOIN the tables & get the data.

Makes the SSIS workflow a bit simpler but obviously requires 2 SQL tables.

Don't forget to clear the tables at the start if you use this method.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top