Solved

BCP.exe SQL Import - Invalid character value for cast specification

Posted on 2016-08-24
8
49 Views
Last Modified: 2016-08-24
Good afternoon,

I have a couple of flat files, with roughly 10K records that I need to import to my MS SQL DB once of twice a week.
I don't have access to the actual server, just access via Management Studio.

So... I am using the BCP command to run this import.  For now, I am testing this out on my local machine before using it in production.
The syntax is (sanitised):

bcp db.dbo.tableOld in E:\datafile.txt -c -r "0x0a" -S myserver-x

It gets through about 50+ records, then gives me the following error:
SQLState = 22005, NativeError = 0
Error = [Microsoft][ODBC Driver 11 for SQL Server]Invalid character value for cast specification
(10 of them, before failing)

I suspect this may have to do with the date field?

Anyway... not sure how to address?

Any assistance would be greatly appreciated.

Thanks,

E.D.
0
Comment
Question by:edalzell01
  • 4
  • 3
8 Comments
 
LVL 12

Assisted Solution

by:funwithdotnet
funwithdotnet earned 250 total points
ID: 41769137
I typically try to import data from a text file into varchar() fields and transform the data one imported. I find it to be easier to handle import issues.

Good luck!
0
 
LVL 26

Accepted Solution

by:
Zberteoc earned 250 total points
ID: 41769149
Can you add a data sample from the flat file that fails? It could also be an encoding issue.

If you use -c switch by itself the BCP assumes tab as a field delimiter. If other character is the delimiter you need to add -t switch, i.e. for comma you will use -t,

Also you should remove the -r"0x0a" unless you know for sure that the row separator is only the new line character, \n, and not carriage return as well, \r!. If ignored the BDP by default will consider both as row separator.
0
 

Author Comment

by:edalzell01
ID: 41769192
Thanks for the advise guys... I found the issue, it wasn't date at all. There are 4 fields that were FLOAT. I changed them to varchar and the import worked perfectly. The only issue is... after I import, I try to change back to FLOAT and I get the following error:

- Unable to modify table.  
Error converting data type nvarchar to float.

Any thoughts? Thanks again guys!
0
 

Author Comment

by:edalzell01
ID: 41769197
I think I found it... the some of the FLOAT values - 10-20, were letters. I assume that's why it wouldn't convert?! :-)
0
VMware Disaster Recovery and Data Protection

In this expert guide, you’ll learn about the components of a Modern Data Center. You will use cases for the value-added capabilities of Veeam®, including combining backup and replication for VMware disaster recovery and using replication for data center migration.

 
LVL 26

Expert Comment

by:Zberteoc
ID: 41769202
Varchar and Nvarchar datatypes "swallow" anything so there is no guarantee that the values imported in them are numerics that can be converted to FLOAT. In other words the input data could contain non numeric values either by mistake or it is just that.
0
 
LVL 26

Expert Comment

by:Zberteoc
ID: 41769208
It is possible to have letters in FLOAT values:

6.02E+12

this is a valid FLOAT value.
0
 
LVL 26

Expert Comment

by:Zberteoc
ID: 41769221
You can identify the non numeric values with:

select * from YourTable where isnumeric(nvarchar_colum)=0
0
 

Author Closing Comment

by:edalzell01
ID: 41769286
I think I've got it, thanks guys!
0

Featured Post

Control application downtime with dependency maps

Visualize the interdependencies between application components better with Applications Manager's automated application discovery and dependency mapping feature. Resolve performance issues faster by quickly isolating problematic components.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
SQL Server Deadlocks 12 50
MS SQL Inner Join - Multiple Join Parameters 2 23
SQL Select Statement 2 22
Trouble analysing a database 9 15
Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
Ever wondered why sometimes your SQL Server is slow or unresponsive with connections spiking up but by the time you go in, all is well? The following article will show you how to install and configure a SQL job that will send you email alerts includ…
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
Using examples as well as descriptions, and references to Books Online, show the different Recovery Models available in SQL Server and explain, as well as show how full, differential and transaction log backups are performed

867 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now