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

Our new SQL Server Forums are live! Come on over! We've restricted the ability to create new threads on these forums.

SQL Server Forums
Profile | Active Topics | Members | Search | Forum FAQ
Save Password
Forgot your Password?

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 Bulk Insert from CSV with comma in field values
 Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

Starting Member

21 Posts

Posted - 07/16/2011 :  09:51:38  Show Profile  Reply with Quote
Hi, I'm currently running into a problem with using BULK INSERT. My CSV file looks like

"1", "john, doe", "0"

I'm using a format file
1 SQLCHAR 0 0 "\",\"" 2 ID SQL_Latin1_General_CP1_CI_AS
2 SQLCHAR 0 1 "\",\"" 2 Name SQL_Latin1_General_CP1_CI_AS
2 SQLCHAR 0 2 "\",\"" 2 IsDeleted SQL_Latin1_General_CP1_CI_AS

Here's my bulk insert statement:
WITH ( firstrow=2,FIELDTERMINATOR=',',datafiletype='widechar',
FORMATFILE=<formatfile> )

This works well if my csv don't contain any fields with commas in it. But if there are data as shown above, it gives me an error:
String or binary data would be truncated.
The statement has been terminated.

Is what I'm doing possible at all? I read from MSDN that data fields can never contain field terminators. But my current implementation is based on this blog ( demonstrating exactly how can this be accomplished using format files.

Appreciate your suggestions.

Starting Member

21 Posts

Posted - 07/16/2011 :  10:24:13  Show Profile  Reply with Quote
never mind, It wasn't the bulk insert causing the error.
Go to Top of Page
  Previous Topic Topic Next Topic  
 Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.04 seconds. Powered By: Snitz Forums 2000