Question : Clean CRLF from text file being imported into SQL2000

Using SQL2000 we have a text file we import which has 16 columns of data, delimited with a ^ and uses a CRLF to signal end of row.

Recently this file has started to come with CRLF's in one of the columns where the description is which is causing our DTS import job to fail.

Is there a way to clean these extra CRLF's out without losing the ending CRLF? It seems the 12th column (Stock_Note) is the one that has these issues so being able to do a find a replace in this column only and make any CRLF's just a space would be ideal.

Just noticed too that whenever one of these rows has the extra CRLF it will also have an extra CRLF after the end of the row which needs to be remove.
I think we just need something that can look at the incoming data and only allow a CRLF after the 15th column.

This would then need to be exported back out to the original txt file format so our normal import job can run.

TIA.

a.

Answer : Clean CRLF from text file being imported into SQL2000

art_r,

Following acperkins's suggestion of an ActiveX task within your DTS package, you could put a code snippet like
this into your procedure:



Dim fso, tsIn, tsOut, TheLine, arr

Set fso = CreateObject("Scripting.FileSystemObject")
Set tsIn = fso.OpenTextFile("c:\EE-Sample.txt")
Set tsOut = fso.CreateTextFile("c:\Corrected.txt", True)

Do Until tsIn.AtEndOfStream
      TheLine = tsIn.ReadLine
      arr = Split(TheLine, "^")
      If TheLine <> "" Then
            If UBound(arr) <> 15 Then TheLine = TheLine & " " & tsIn.ReadLine
            tsOut.WriteLine TheLine
      End If
Loop

tsIn.Close
tsOut.Close

Set tsIn = Nothing
Set tsOut = Nothing
Set fso = Nothing


That appeared to work for me when run as a *.vbs file.

Patrick
Random Solutions  
 
programming4us programming4us