Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Flat file source - split delimited address field to additional fields.

Status
Not open for further replies.

ChrisMarin

Technical User
Oct 14, 2002
23
0
0
GB
A client of ours can only export data in the following .csv delimited format:

ID, Name, Company, Address, Town, County, Postcode, Country

The Address field contains anything from 1 to 5 lines of local address data separated by Carriage Return.

We need to get this data into our SQL database using SSIS on a daily basis.

I have managed to import the file as Flat File, and have successfully changed the Carriage Returns in the Address field to commas.

I now have data in the Address field that represents:

Address
"20 Test Street, Testville"
"22 Test Avenue"
"Flat 2, 41 Test Close, Testville"

I would like the data to look like:

Add1,Add2,Add3,Add4,Add5
20 Test Street,Testville,,,
22 Test Avenue,,,,
Flat 2, 41 Test Close, Testville,,
Flat 5, Test House, Test close, Test Road, Testville

I have tried using Derived Columns and the FindString and SubString commands, but I can't seem to get it to work because of the differing number of commas in each record. Sometimes there are none (second row in above examples) and sometimes more (other rows in above example).

To get the first value in the field I tried:
SUBSTRING(AddressCommas,1,(FINDSTRING(AddressCommas,",",1) - 1))

but as stated it doesn't work with the differing number of commas.

Are there any other ways I can go about this?

Note: the client has no control over the quality of their data.

 
with SSIS the easier would be to do a C# script and do the string manipulation on it, and output 1 or more columns based on your own decision - doing it with plain derived columns will be harder and performance will be slower

Or do it on a staging table on SQL - again its easy enough to create a table function to do the split

Regards

Frederico Fonseca
SysSoft Integrated Ltd

FAQ219-2884
FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top