Solved

How to ignore Header and Footer row when doing DTS transformation

Posted on 2006-06-23
6
299 Views
Last Modified: 2008-02-26
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
0
Comment
Question by:Karuppaiah
  • 2
6 Comments
 
LVL 75

Accepted Solution

by:
Anthony Perkins earned 63 total points
ID: 16973647
There are several alternatives, but the best way is to always import into a staging table, prior to validating and moving the data into the final production tables.
0
 
LVL 3

Expert Comment

by:chhapia_chintak
ID: 16981573
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





0
 
LVL 3

Assisted Solution

by:chhapia_chintak
chhapia_chintak earned 62 total points
ID: 16981595
Aslo remove message box from the scripts and write nothing in palce on "".

Fineal script is
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
select Case strLine
       case "TEST HEADER"

        case "TEST Footer"

        case ""

        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
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction In my previous article (http://www.experts-exchange.com/Microsoft/Development/MS-SQL-Server/SSIS/A_9150-Loading-XML-Using-SSIS.html) I showed you how the XML Source component can be used to load XML files into a SQL Server database, us…
Ever wondered why sometimes your SQL Server is slow or unresponsive with connections spiking up but by the time you go in, all is well? The following article will show you how to install and configure a SQL job that will send you email alerts includ…
Viewers will learn how to use the INSERT statement to insert data into their tables. It will also introduce the NULL statement, to show them what happens when no value is giving for any given column.
Viewers will learn how to use the SELECT statement in SQL to return specific rows and columns, with various degrees of sorting and limits in place.

831 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question