Naveen Kumar
Naveen Kumar

Reputation: 632

Loading Comma Separated csv file to table in SSIS

I have a csv file with below formatted data.

File: Sample.csv

Id,Name,Address

1,Abcd,street1,3rdcross,xxxx

2,Cfre,2ndmain,3rdstreet,yyy

3,Asdf,4thmain,1stcross,zzz

Need to load the data to table like below.

Table: Sample

Id Name Address

1 Abcd street1,3rdcross,xxxx

2 Cfre 2ndmain,3rdstreet,yyy

3 Asdf 4thmain,1stcross,zzz

How to acheive this using SSIS ?

If we use a comma delimiter, then the address column will split into 3 columns.

Upvotes: 1

Views: 1873

Answers (3)

sam
sam

Reputation: 1294

This can be done from derived column transformation by follwing the following steps:

  1. In Flat File Connection Manager select format as Ragged Right and not delimited. So your data will be coming in one column
  2. select derived column transformation. create 3 columns in this transformation with the below mentioned formula's:

    ID - SUBSTRING([Id,Name,Address],1,FINDSTRING([Id,Name,Address],",",1) - 1)
    
    Name - SUBSTRING([Id,Name,Address],FINDSTRING([Id,Name,Address],",",1) + 1,FINDSTRING([Id,Name,Address],",",2) - FINDSTRING([Id,Name,Address],",",1) - 1)
    
    Address - SUBSTRING([Id,Name,Address],FINDSTRING([Id,Name,Address],",",3) + 1,LEN([Id,Name,Address]))
    

This is how you can get three seperate columns from the text file.

Upvotes: 0

KeithL
KeithL

Reputation: 5594

If you your data is consistently 5 columns but your header isn't then skip row 1 and name the columns as you want.

Possibly:

Id,Name,Address,Directions,[Blah]

If you really want to put those back into a "," delimited field as you stated then used derived column and concatenate.

new column = Address + "," + Directions + "," + [Blah]

Upvotes: 1

Naveen Kumar
Naveen Kumar

Reputation: 632

Initially when Text Qualifier is set to none, the columns are separated.

enter image description here

When changed Text Qualifier to double quoted " then it was perfect.

enter image description here

Upvotes: 1

Related Questions