Reputation: 641
I have a table customer in my sql server.
Columns
we receive customer files from the distributor on a monthly basis. so sometimes they send files with the wrong structuer.. like maybe gstin is missing or dl_number is missing or gstin is in place of dl_number and dl_number is in place of tel...basically, columns could be split..
when we upload those flat files with SSIS it gives error..and data doesn't get uploaded on the server if the structure is wrong.
I want to upload those data with null data if columns are missing or columns are misplaced.
Upvotes: 3
Views: 1757
Reputation: 37313
Based on your comment, you are handling with flat files. To solve this problem, you have to read all columns as one column and retrieve the structure on the go.
Dataflow task
Dataflow task
add a Flat File source, a script component and an OLEDB destination.Inside the script write the following code.
Dim Distributer_Code as integer = -1
Dim Cust_code as integer = -1
Dim cust_name as integer = -1
Dim cust_add as integer = -1
Dim zip as integer = -1
Dim tel as integer = -1
Dim dl_number as integer = -1
Dim gstin as integer = -1
Dim intRowIndex as integer = 0
Public Overrides Sub Input0_ProcessInputRow(ByVal Row As Input0Buffer)
If intRowIndex = 0 then
Dim strfields() as string = Row.Column0.split(CChar("|"))
Dim idx as integer = 0
For idx = 0 To strFields.length - 1
Select case str
Case "Distributer_Code"
Distributer_Code = idx
Case "Cust_code"
Cust_code = idx
Case "cust_name"
cust_name = idx
Case "cust_add"
cust_add = idx
Case "zip"
zip = idx
Case "tel"
tel = idx
Case "dl_number"
dl_number = idx
Case "gstin"
gstin = idx
End Select
Next
Else
Dim strfields() as string = Row.Column0.split(CChar("|"))
If Distributer_Code > -1 Then Row.DistributerCode = strfields(Distributer_Code)
If Cust_code > -1 Then Row.Custcode = strfields(Cust_code)
If cust_name > -1 Then Row.custname = strfields(cust_name)
If cust_add > -1 Then Row.custadd = strfields(cust_add)
If zip > -1 Then Row.zip = strfields(zip)
If tel > -1 Then Row.tel = strfields(tel)
If dl_number > -1 Then Row.dlnumber = strfields(dl_number)
If gstin > -1 Then Row.gstin = strfields(gstin)
End If
intRowIndex += 1
End Sub
Map the output columns to the OLEDB Destination
Upvotes: 2