Solved

BULK IMPORT German date format to English SQL Server

Posted on 2007-12-02
9
1,888 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
Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

 
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

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

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

Why is this different from all of the other step by step guides?  Because I make a living as a DBA and not as a writer and I lived through this experience. Defining the name: When I talk to people they say different names on this subject stuff l…
How to install Selenium IDE and loops for quick automated testing. Get Selenium IDE from http://seleniumhq.org Go to that link and select download selenium in the right hand column That will then direct you to their download page. From that p…
Via a live example, show how to setup several different housekeeping processes for a SQL Server.
Viewers will learn how the fundamental information of how to create a table.

734 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