Link to home
Start Free TrialLog in
Avatar of Karuppaiah
Karuppaiah

asked on

How to ignore Header and Footer row when doing DTS transformation

Hi,
I am exporting the data from the text file. I am using Local Package for this to do every week. The text file has header and footer information (First and last row). I need to prevent them entering into database. I am getting error while running this package as these header and footer are also inserting.

Thanks for your help!

With Regards,
Karu
ASKER CERTIFIED SOLUTION
Avatar of Anthony Perkins
Anthony Perkins
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
You can put Active X script before the actual transformation.

That activeX do following things:
- script read each line from file.
- Matches it with header string and footer string
- It found replace it with nothing.
- If not then copy the contants to temp file.
- At end delete the main file and save temp file as main file.

following is a ActiveX script for this :
But cahnge the path of main file (strFldr) and temp file (strFldr) as required or you can pass it from global variable.
Also change header and footer strings in Case statments accordingly.


Function Main()
Dim objFSO       
Dim fle1      
Dim fle2      
Dim strPath      
Dim strFldr      
Dim strLine      

strPath = "c:\1.txt"
strFldr = "C:\temp.txt"

set objFSO = CreateObject("Scripting.FileSystemObject")

if not objFSO.FileExists(strPath) then 'The file to copy is not present
        msgbox "The " & strPath & " file was not found on this computer"
end if

if objFSO.FileExists(strFldr) then
        objFSO.DeleteFile(strFldr) 'If the temp file is found, delete it
end if

set fle1 = objFSO.OpenTextFile(strPath)

set fle2 = objFSO.CreateTextFile(strFldr) 'Create the temp file

Do while not fle1.AtEndofStream
strLine = fle1.ReadLine
MsgBox(strLine)
select Case strLine
      case "TEST HEADER"
                fle2.WriteLine ""
        case "TEST Footer"
            fle2.WriteLine ""
        case ""
            fle2.WriteLine ""
      case else
                fle2.WriteLine strLine
end select
loop
       
fle1.close
set fle1 = nothing
fle2.close
set fle2 = nothing
       
objFSO.DeleteFile strPath, true    
       
objFSO.MoveFile strFldr, strPath


      Main = DTSTaskExecResult_Success
End Function





SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial