dbTalk Databases Forums  

bulk insert troubles

comp.databases.ms-sqlserver comp.databases.ms-sqlserver


Discuss bulk insert troubles in the comp.databases.ms-sqlserver forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
ableport@gmail.com
 
Posts: n/a

Default bulk insert troubles - 07-27-2010 , 12:53 PM






Hello,

I am trying to load a csv file using bulk insert. Everything goes fine
but no data is loaded! All I get is a message saying "(0 row(s)
affected)". Any idea what s going on?


Set up:
create table dbo.test (member_id varchar (50),
prod_name varchar(50), prod_score varchar(50))


SQL:
bulk insert dbo.test
from 'C:/temp/test.csv'
with (FIRSTROW = 2,FORMATFILE = 'C:/temp/my-format.fmt')


Format File: my-format.fmt
9.0
3
1 SQLCHAR 0 50 "\",\"" 1 member_id SQL_Latin1_General_CP1_CI_AS
2 SQLCHAR 0 50 "\",\"" 2 prod_name SQL_Latin1_General_CP1_CI_AS
3 SQLCHAR 0 50 "\"\r\n" 3 prod_score SQL_Latin1_General_CP1_CI_AS


Data file:
2,a,3
2,b,1
2,c,5
3,a,3
3,b,4
3,c,0

Reply With Quote
  #2  
Old   
Erland Sommarskog
 
Posts: n/a

Default Re: bulk insert troubles - 07-27-2010 , 04:28 PM






(ableport (AT) gmail (DOT) com) writes:
Quote:
I am trying to load a csv file using bulk insert. Everything goes fine
but no data is loaded! All I get is a message saying "(0 row(s)
affected)". Any idea what s going on?
...
Format File: my-format.fmt
9.0
3
1 SQLCHAR 0 50 "\",\"" 1 member_id
SQL_Latin1_General_CP1_CI_AS
2 SQLCHAR 0 50 "\",\"" 2 prod_name
SQL_Latin1_General_CP1_CI_AS
3 SQLCHAR 0 50 "\"\r\n" 3 prod_score
SQL_Latin1_General_CP1_CI_AS


Data file:
2,a,3
2,b,1
2,c,5
3,a,3
3,b,4
3,c,0
The format file does not match the data file. The file uses only comma
as delimiter, but according to your format file, the file is expected
to look like this:


2","a","3"
2","b","1"
2","c","5"
3","a","3"
3","b","4"
3","c","0"




--
Erland Sommarskog, SQL Server MVP, esquel (AT) sommarskog (DOT) se

Links for SQL Server Books Online:
SQL 2008: http://msdn.microsoft.com/en-us/sqlserver/cc514207.aspx
SQL 2005: http://msdn.microsoft.com/en-us/sqlserver/bb895970.aspx
SQL 2000: http://www.microsoft.com/sql/prodinf...ons/books.mspx

Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.