Solved

BULK IMPORT German date format to English SQL Server

Posted on 2007-12-02
9
1,838 Views
Last Modified: 2013-11-06
Hi experts,

I'm trying to import an MS Excel generated CSV into MS SQL 2005 Express.
The CSV contains some data in German data format, e.g. 13.01.2008 (compared to 01.13.2008 US English). The corresponding field in the SQL 2005 destination table is defined as "DateTime".

My sql statemement for running a bulk import looks like that:
BULK INSERT SalesData FROM C:\import.csv WITH (FIELDTERMINATOR = ';', ROWTERMINATOR = '\r\n', TABLOCK, FIRSTROW = 2, KEEPNULLS, CODEPAGE='ACP')

This works fine as long as all data is in English date format. But as I said: my data is in German date format, and I receive the following error message: [...] Cannot fetch a row from OLE DB provider "BULK" for linked server "(null)". The OLE DB provider "BULK" for linked server "(null)" reported an error. The provider did not give any information about the error. Cannot bulk load because the maximum number of errors (10) was exceeded. Bulk load data conversion error (type mismatch or invalid character for the specified codepage) for row 16, column 15 (myDateField). [...]

What can I do? Is there any way to tell SQL Server to convert the German date format to US date format before importing?

Thanks so much for any help!
Ingmar
0
Comment
Question by:softwarea
  • 4
  • 4
9 Comments
 
LVL 11

Expert Comment

by:deroby
ID: 20391638
maybe you could load the data first into a staging table where the datefields are replaced by varchar fields. Once the table is loaded, copy the data and use the Convert(datetime, <date-string>, 104) for each field to convert... bit more work, but should work nicely...
0
 

Author Comment

by:softwarea
ID: 20394017
Hi deroby,
thanks for your help. Sorry, I should have been more precise: I'm looking for a "direct" solution without staging tables or source file manipulations. I was just hoping I missed someting about SQL Server or the bulk insert statement. If you (or anybody else) do not have any other idea I have no chnace but doing exactly what you suggested.
Thanks again!
Ingmar
0
 
LVL 11

Expert Comment

by:deroby
ID: 20394799
I'm not too familiar with the BULK INSERT statement, but I fear it is rather 'strict' about (a lot of) things, just like bcp.exe

Maybe you could try to 'fiddle' with the 'formatfile', but so far I've not been able to 'tweak' a datetime column into any particalar format :

=> bcp database..table format nul -T -c -x -f myformatfile.xml

creates the .xml file, but I do not see how I can tell it to use convert(datetime, <data>, 108) instead of whatever is the current default...

That said, would it help if you put SET LANGUAGE / 'reset' LANGUAGE around the BULK INSERT statement ??

DECLARE @prev_language

SELECT @prev_language = @@language
 

SET LANGUAGE 'Deutsch'
 

BULK INSERT etc..
 

SET LANGUAGE @prev_language

Open in new window

0
 
LVL 69

Accepted Solution

by:
ScottPletcher earned 500 total points
ID: 20396411
Please run statement below before issuing the BULK INSERT command.
SET DATEFORMAT dmy

Open in new window

0
U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

 

Author Comment

by:softwarea
ID: 20396765
Hi Scott,
YES, that's it. Perfect!!! Thanks so much.

@deroby: You made every effort to help me, and maybe your solution works too. I didn't try it though 'cause Scott's was a little easier to implement. So, thanks again for your help!!!
0
 
LVL 11

Expert Comment

by:deroby
ID: 20397334
grin, imho

SET DATEFORMAT dmy

or

SET LANGUAGE 'German'

is about the same thing, effortwise =)

But never mind, I'm glad it works... Good to know that BULK INSERT "listens" to this setting ... I rather learn than get points .. I think =P
0
 

Author Comment

by:softwarea
ID: 20397364
Ups, I'm really sorry, deroby. I apologize for having not tried your solution too. :-(
0
 
LVL 11

Expert Comment

by:deroby
ID: 20397397
like I said : never mind!!  

FWIW : I'll try to be more convincing next time ... like add flashy pictures and give-away gizmo's to my solutions =P
0
 

Author Comment

by:softwarea
ID: 20397412
;-))) Yes please. Can't wait. Shall I think of a new weird question?
Thanks for your effort and sympathy!
0

Featured Post

NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

Question has a verified solution.

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

Slowly Changing Dimension Transformation component in data task flow is very useful for us to manage and control how data changes in SSIS.
For both online and offline retail, the cross-channel business is the most recent pattern in the B2C trade space.
Via a live example, show how to setup several different housekeeping processes for a SQL Server.
The viewer will learn how to use and create keystrokes in Netbeans IDE 8.0 for Windows.

912 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

17 Experts available now in Live!

Get 1:1 Help Now