Adding header and footer to dts text export SQL Server 2000

  • I'm sure this is a standard task, but I can find little information on how to do this.  I tried writing a 13 character header and 13 character footer as first and rows to a table, but when that is exported to a text file you get blanks to the end of the line.  I need a header and footer each 13 character long.  Is Active X the only way to do this?  If so, does anyone have any sample scripts?

    Help is much appreciated.

    Thanks, Arthur

     

     

  • There are a couple of ways this could be done.   Here's one.  After your file has been created, add Active X script task that uses the FileSystem Object to write a new file with a header & footer, and copy the contents of your original file into it.

    Function Main()

     Dim objFSO

     Dim strSource

     Dim strDestination

     Dim strLine

     Const ForReading = 1

     Set objFSO = CreateObject("Scripting.FileSystemObject")

     strSource = "c:\data.txt"

     strDestination = "c:\finalfile.txt"

     If objFSO.FileExists(strSource) Then

      Dim objSourceFile

      Dim objDestinationFile

      Set objSourceFile = objFSO.OpenTextFile(strSource, ForReading)

      Set objDestinationFile = objFSO.CreateTextFile(strDestination, True)

      objDestinationFile.WriteLine "13char header"

      Do While objSourceFile.AtEndOfStream = False

       strLine = objSourceFile.ReadLine

       objDestinationFile.WriteLine strLine

      Loop

     

      objDestinationFile.WriteLine "13char footer"

      objDestinationFile.Close

      objSourceFile.Close

      Set objDestinationFile = Nothing

      Set objSourceFile = Nothing

     End If

     Set objFSO = Nothing

     Main = DTSTaskExecResult_Success

    End Function

  • Hi Erik,

    This is great!  Thanks!  I found another sample script since I posted that does the same thing, but this is neater.

    Much appreciated,  Arthur

Viewing 3 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply