April 3, 2008 at 10:50 am
I have a variable length flat file that is defined by a "record type" value (first two characters in each row), for example:
01value1value2value3valueINEEDvalue4value5
02newval1newval2newval3
03anotherval1
04differentval1differentval2differentval3differentval4differentval5differentval6
I can read the source file using a "flat file source", use a "script component" to break the file row into 2 columns ( rectype and rowdata), I can then use a "conditional split" to push the data to different destination sources (tables - flat files).
The problem is that the file has to be processed sequentially, there is a value, or column, in the "01" record type rows that I need to relate the following record type rows to the "parent" (01 record type rows). How can I grab a value from one column in the "01" type rows, and add that value as an new column in the Non 01 rows?
column I need is listed as "valueINEED"
example output:
01value1value2value3valueINEEDvalue4value5
02newval1newval2newval3valueINEED
03anotherval1valueINEED
04differentval1differentval2differentval3differentval4differentval5differentval6valueINEED
April 3, 2008 at 12:00 pm
Michael Covington (4/3/2008)
I have a variable length flat file that is defined by a "record type" value (first two characters in each row), for example:01value1value2value3valueINEEDvalue4value5
02newval1newval2newval3
03anotherval1
04differentval1differentval2differentval3differentval4differentval5differentval6
I can read the source file using a "flat file source", use a "script component" to break the file row into 2 columns ( rectype and rowdata), I can then use a "conditional split" to push the data to different destination sources (tables - flat files).
The problem is that the file has to be processed sequentially, there is a value, or column, in the "01" record type rows that I need to relate the following record type rows to the "parent" (01 record type rows). How can I grab a value from one column in the "01" type rows, and add that value as an new column in the Non 01 rows?
column I need is listed as "valueINEED"
example output:
01value1value2value3valueINEEDvalue4value5
02newval1newval2newval3valueINEED
03anotherval1valueINEED
04differentval1differentval2differentval3differentval4differentval5differentval6valueINEED
You don't necessarily need a script for that. Assuming there's a way to identify the pattern (your test data doesn't give me a hint on how to), take a look at what I posted over in this thread.
http://www.sqlservercentral.com/Forums/FindPost478822.aspx
You can then use the derived column transform to parse the stuff, and then your data "stays" with the identity column.
----------------------------------------------------------------------------------
Your lack of planning does not constitute an emergency on my part...unless you're my manager...or a director and above...or a really loud-spoken end-user..All right - what was my emergency again?
April 3, 2008 at 12:45 pm
It was a simple fix... All I did was create a public property in the script component, add an if statement to test the record type, if it was "01" I set the property value to equal the id number that I needed from that row, and then pass that value back with the other columns.
Dim strRow As String
Dim strRowCaseID As String
Try
If (Row.RowContent.Length > 0) Then
strRow = Row.RowContent.ToString()
If (strRow.Length > 0) Then
Row.RecType = strRow.Substring(0, 2)
Row.RowData = Row.RowContent.ToString()
If (strRow.Substring(0, 2) = "01") Then
_rowCaseNumber = strRow.Substring(17, 4) + strRow.Substring(21, 3).TrimEnd() + strRow.Substring(24, 6)
End If
Row.RowCaseID = _rowCaseNumber.ToString()
End If
End If
Catch ex As Exception
System.Windows.Forms.MessageBox.Show(Row.RowContent)
End Try
Viewing 3 posts - 1 through 2 (of 2 total)
You must be logged in to reply to this topic. Login to reply