SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

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

alasse130
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:
BULK INSERT FROM <filename>
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 (http://lanestechblog.blogspot.com/2008/08/sql-server-bulk-insert-using-format.html) demonstrating exactly how can this be accomplished using format files.

Appreciate your suggestions.

alasse130
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  
 New 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.05 seconds. Powered By: Snitz Forums 2000