Solved

How to ignore Header and Footer row when doing DTS transformation

Posted on 2006-06-23
6
297 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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

In this article—a derivative of my DaytaBase.org blog post (http://daytabase.org/2011/06/18/what-week-is-it/)—I will explore a few different perspectives on which week today's date falls within using Microsoft SQL Server. First, to frame this stu…
Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…
Via a live example, show how to extract information from SQL Server on Database, Connection and Server properties
Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.

743 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now