Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2008 Forums
 SSIS and Import/Export (2008)
 Importing CSV in SSIS 2008

Author  Topic 

SergioM
Posting Yak Master

170 Posts

Posted - 2011-10-08 : 01:23:45
I'm trying to import a CSV file in SSIS 2008, but I'm having an issue with the comma as a delimiter. Every cell is enclosed in quotation marks & a comma divides them, however there are also commas within the data. As a result, the output is skewed.

The file is written something like this:
"Part Number", "Brand","Quantity","Price","Description","Return Policy"
"Playstation","Sony","2","505.30","This is a game console","yes"
"Ipod","Apple","2","300.30","This device can play MP3, MP4, and MOV files","yes"
"Zen","Creative","40","44.48","This is an MP3 player","yes"
"HDJ-2000","Pioneer","20","150.88","This is a high end headphone","yes"


But the output looks like this because the commas are throwing it off:
Part Number	Brand	Quantity	Price	Description	Return Policy	
Playstation Sony 2 505.3 This is a game console yes
Ipod Apple 2 300.3 This device can play MP3 MP4 and MOV files
Zen Creative 40 44.48 This is an MP3 player yes
HDJ-2000 Pioneer 20 150.88 This is a high end headphone yes


Is there any way to tell SSIS that only the commas within the quotation marks are delimiters? Microsoft Excel interprets the file correctly without an issue.

EDIT: The output is less than clear. In row #2, the "Description" Field has commas within it and that throws off the input of the "Return Policy" field and anything thereafter.

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2011-10-08 : 03:19:06
i think best way to import this csv is to use BULK INSERT with a format file.

See
http://www.nigelrivett.net/SQLTsql/BCP_quoted_CSV_Format_file.html

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

Villanuev
Constraint Violating Yak Guru

478 Posts

Posted - 2011-10-19 : 02:51:27
Yes. Its true, use Bulk Insert. faster than SSIS.

Here is my sample as your reference.

Use YOURDB
Bulk Insert #VPTable --temp table
From '\\Pdcvcssql001nd4\Material Planning\VP309130.csv'--point to your folderfile
With
(
DATAFILETYPE = 'char',
FieldTerminator = ',',
CODEPAGE = 'OEM',
KEEPNULLS,
RowTerminator = '\n', FirstRow = 1)


Note:


JOV
Go to Top of Page

DeepakD
Starting Member

5 Posts

Posted - 2011-10-28 : 02:30:22
Hi,

In SSIS we have a property called text qualifier ,If you set the text qualifier as " the problem will fix.
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2011-10-28 : 05:33:42
quote:
Originally posted by DeepakD

Hi,

In SSIS we have a property called text qualifier ,If you set the text qualifier as " the problem will fix.



definitely you can fix the problem. but most occasions BULK INSERT performs much faster than SSIS and format file gives you more flexibility in getting data from custom qualifier and delimited formats

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -