Solved

BULK IMPORT German date format to English SQL Server

Posted on 2007-12-02
9
1,870 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
Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

 
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

MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
ms sql and asp dates 5 42
connection to SQL 2012 error in windows 10 18 46
sql server connection string in config file 4 41
Remove () 10 40
This article shows gives you an overview on SQL Server 2016 row level security. You will also get to know the usages of row-level-security and how it works
In this article we will learn how to fix  “Cannot install SQL Server 2014 Service Pack 2: Unable to install windows installer msi file” error ?
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function
Viewers will learn how to use the SELECT statement in SQL to return specific rows and columns, with various degrees of sorting and limits in place.

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