Here is the solution that I figured out, if anyone is interested.
The tip about using a global variable enumerator to keep track of the line
(1 - 4) within the record I am reading was good. Thanks Ilya & Allan!
Then I created a activex script transform that has the full text column as
input and all the database columns as output.
In the script I put a Switch Case statement that based on the value of the
global enumerator, extracts the interesting parts of the source data and
sets the destination fields. After this it returns
DTSTransformStat_SkipInsert for the first three lines. Only the 4th line
returns DTSTransformStat_OK and this results in one insert for every 4 lines
and the field contents seems to be correct.
Here is a sample:
Function Main()
Select Case DTSGlobalVariables("RowEnum").Value
Case 1 ' Get fields on the first line of the multi line record
DTSDestination("Col1FromRow1") = Left(DTSSource("Col001"), 6)
DTSDestination("Col2FromRow1") = Mid(DTSSource("Col001"), 7, 6)
DTSDestination("Col3FromRow1") = Mid(DTSSource("Col001"), 13, 10)
DTSDestination("Col4FromRow1") = Mid(DTSSource("Col001"), 23, 13)
DTSGlobalVariables("RowEnum").Value = DTSGlobalVariables("RowEnum").Value
+1
Main = DTSTransformStat_SkipInsert
Case 2 ' Get fields on the secondline of the multi line record
DTSDestination("Col1FromRow2") = Left(DTSSource("Col001"), 35)
DTSDestination("Col2FromRow2") = Mid(DTSSource("Col001"), 36, 30)
DTSDestination("Col3FromRow2") = Mid(DTSSource("Col001"), 66, 30)
DTSGlobalVariables("RowEnum").Value = DTSGlobalVariables("RowEnum").Value
+1
Main = DTSTransformStat_SkipInsert
Case 3 Get fields on the thirdline of the multi line record
DTSDestination("Col1FromRow3") = Left(DTSSource("Col001"), 5)
DTSDestination("Col2FromRow3") = Mid(DTSSource("Col001"), 6, 8)
DTSGlobalVariables("RowEnum").Value = DTSGlobalVariables("RowEnum").Value
+1
Main = DTSTransformStat_SkipInsert
Case 4 Get fields on the last line of the multi line record
DTSDestination("Col1FromRow4") = Left(DTSSource("Col001"), 6)
DTSDestination("Col2FromRow4") = Mid(DTSSource("Col001"), 7, 6)
DTSDestination("Col3FromRow4") = Mid(DTSSource("Col001"), 13, 6)
DTSGlobalVariables("RowEnum").Value = 1
Main = DTSTransformStat_OK
End Select
End Function
Best regards,
Per Salmi
"Allan Mitchell" <allan@no-spam.sqldts.com> skrev i meddelandet
news:OHU5na9qEHA.2636@TK2MSFTNGP09.phx.gbl...
[quoted text, click to view] > OK
>
> You have an enumerator variable in your Active Script transform. Its
> values are 1-4
>
> You grab the values from each row of your text file
>
> For values 1-3 you do not insert anything to the DB
>
> For 4 you can then issue an insert with the values you have accumulated
> over the last 4 rows of the file
>
> --
>
> Allan Mitchell MCSE,MCDBA, (Microsoft SQL Server MVP)
>
www.SQLDTS.com - The site for all your DTS needs.
>
www.Konesans.com >
>
> "Per Salmi" <per.salmi@nospam.nospam> wrote in message
> news:OBDARt4qEHA.3520@TK2MSFTNGP11.phx.gbl...
>>I am going to import a textfile from a mainframe system that is formatted
>>with fields in fixed column positions. But there is another thing that
>>bothers me, every record in the file is split up on four rows in the file.
>>I want to use fields from the 4 lines and compose input for a single row
>>in a database.
>>
>> Anyone out there who knows how to perform this multi-line record reading
>> of a textfile?
>>
>> Or should I avoid DTS and go for a C# application because of the
>> multi-line input records?
>>
>> Best regards,
>> Per Salmi
>>
>
>