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
 General SQL Server Forums
 New to SQL Server Programming
 bcp copy

Author  Topic 

-Dman100-
Posting Yak Master

210 Posts

Posted - 2009-01-04 : 13:59:54
I'm trying to copy a csv file using bcp into table, but I'm getting errors.

The first error I got was:

Unexpected EOF encountered in BCP data-file

I think this is because I didn't specify the field and row terminator correctly.

Then I think I fixed the problem with the field and row terminators, but then when I ran the bcp insert, I was prompted for the file storage type, prefix-length (not sure what to enter for this) and field terminator.

I got the following error:

Numeric value out of range


Here is a sample of rows from the csv file I'm trying to import:

Acct#,Contract#,StartDate,EndDate,ProductCode,PricebookEntryId,Quantity,TotalPrice,Category,SubCategory,Description
13112,JDE Contract Number 202159-00-2007,10/1/2006,9/30/2007, Exclude,,1,0,,,Compass Station Access BaseCnt 15
13112,JDE Contract Number 202159-00-2007,10/1/2006,9/30/2007, SWCLASSIC,,1,0,,,C-PAS K-8
13112,JDE Contract Number 202159-00-2007,10/1/2006,9/30/2007, SWCLASSIC,,1,0,,,Golden Book Encyclopedia (WIN)
13112,JDE Contract Number 202159-00-2007,10/1/2006,9/30/2007, SWCLASSIC,,1,0,,,Integrated Lang. Arts: Primary
13112,JDE Contract Number 202159-00-2007,10/1/2006,9/30/2007, SWCLASSIC,,1,0,,,Language Arts Level 3

The first row is the headers, which I can remove, but I included to help show all the fields. Each field is terminated by a comma and the row is terminated by a line-break.

The datatypes for all the columns are nvarchar except for the quantity, which is a float and the amount, which is currency.

This was what I tried:
bcp <databasename>.dbo.<tablename> in c:\<filename.csv> -t , -r \n -S ServerName -U username -P password

Thanks for any help.

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2009-01-04 : 14:05:22
The first problem is that you have the column headers in the file. So either remove the first row or you'll need to skip it using the -F switch (-F 2)

Without actually having the csv file in our possession, it's hard to know if your file is formatted correctly. Use a hex editor to verify that all rows have problem row terminators and that the file has a proper EOF terminator.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page
   

- Advertisement -