Solved

BULK IMPORT German date format to English SQL Server

Posted on 2007-12-02
9
1,899 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

 
LVL 69

Accepted Solution

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

Open in new window

0
 

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

Get MySQL database support online, now!

At Percona’s web store you can order your MySQL database support needs in minutes. No hassles, no fuss, just pick and click. Pay online with a credit card.

Question has a verified solution.

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

The Delta outage: 650 cancelled flights, more than 1200 delayed flights, thousands of frustrated customers, tens of millions of dollars in damages – plus untold reputational damage to one of the world’s most trusted airlines. All due to a catastroph…
A Stored Procedure in Microsoft SQL Server is a powerful feature that it can be used to execute the Data Manipulation Language (DML) or Data Definition Language (DDL). Depending on business requirements, a single Stored Procedure can return differe…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
Viewers will learn how to use the UPDATE and DELETE statements to change or remove existing data from their tables. Make a table: Update a specific column given a specific row using the UPDATE statement: Remove a set of values using the DELETE s…

630 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