Solved

How to ignore Header and Footer row when doing DTS transformation

Posted on 2006-06-23
6
302 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

Question has a verified solution.

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

Suggested Solutions

Everyone has problem when going to load data into Data warehouse (EDW). They all need to confirm that data quality is good but they don't no how to proceed. Microsoft has provided new task within SSIS 2008 called "Data Profiler Task". It solve th…
In this article we will learn how to fix  “Cannot install SQL Server 2014 Service Pack 2: Unable to install windows installer msi file” error ?
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
Via a live example combined with referencing Books Online, show some of the information that can be extracted from the Catalog Views in SQL Server.

752 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