Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

How to ignore Header and Footer row when doing DTS transformation

Posted on 2006-06-23
6
Medium Priority
?
304 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 252 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 248 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

Get your Conversational Ransomware Defense e‑book

This e-book gives you an insight into the ransomware threat and reviews the fundamentals of top-notch ransomware preparedness and recovery. To help you protect yourself and your organization. The initial infection may be inevitable, so the best protection is to be fully prepared.

Question has a verified solution.

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

In the first part of this tutorial we will cover the prerequisites for installing SQL Server vNext on Linux.
Recently we ran in to an issue while running some SQL jobs where we were trying to process the cubes.  We got an error saying failure stating 'NT SERVICE\SQLSERVERAGENT does not have access to Analysis Services. So this is a way to automate that wit…
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function
Via a live example, show how to setup several different housekeeping processes for a SQL Server.

705 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