I am trying to insert some values in a table through BCP-IN by executing batch file.But facing this issue-
Starting copy...
SQLState = 22008, NativeError = 0
Error = [Microsoft][SQL Server Native Client 10.0]Invalid date format
SQLState = 22008, NativeError = 0
Error = [Microsoft][SQL Server Native Client 10.0]Invalid date format
SQLState = 22008, NativeError = 0
Error = [Microsoft][SQL Server Native Client 10.0]Invalid date format
SQLState = 22005, NativeError = 0
The file thorugh which data getting inserted is like this-
Marcus, Tom 371332 11-1-09 0:00 720.04 25.2 108.01 0 43.2
And the table in which data getting inserted having coloumn-
EFFECT_DATE2] [datetime2](3) NULL,
Any suggestion how to avoid this error?
You may want to check the default language settings for the target database, as that is used to interpret dates i.e. DATEFORMAT.
A solution would be reformat the date into ISO Standard format (YYYYMMDD) in the data file.
Alternatives would be either reformat the date to match the DATEFORMAT of the target database or change the DATEFORMAT by changing the database's default language setting.
See https://support.microsoft.com/en-us/kb/173907
As noted in the KB, changing the server's regional setting in the Control Panel will not change how Sql Server interprets the dates.
Try using SQLCHAR in format file instead of SQLDATETIME. Set data in datetime field into your local format and use -R key for bcp.exe run.
来源:https://stackoverflow.com/questions/15405052/bcp-in-error-microsoftsql-server-native-client-10-0invalid-date-format