SQL Server BULK INSERT error when importing from txt file. SQL converts dates from dd/mm/yy to mm/dd/yy

yc0p9oo0  于 2023-10-15  发布在  其他
关注(0)|答案(1)|浏览(116)

I'm having the problem described above. Because of this I'm getting an error everytime the day is higher than 12.

This is the query.

BULK INSERT table_name 
FROM 'filedirectory.txt' 
WITH (FIELDTERMINATOR = '\t',
      ROWTERMINATOR = '\n', 
      FIRSTROW = 2)

This is the message I get when the day exceeds 12.

Msg 4864, Level 16, State 1, Line 1
Bulk load data conversion error (type mismatch or invalid character for the specified codepage) for row 1992, column 20 (DATE)

The value for column 20 row 1992 or higher is 13/08/2023 or more, which sql reads as '8 of december+1', resulting in error.

Any help will be much appreciated.

This is the row from which the error message appears.

ROW DATE
1991    12/09/2023 18:00
***1992 13/09/2023 09:00***
1993    13/09/2023 09:00
1994    13/09/2023 09:01
1995    13/09/2023 09:01
1996    13/09/2023 09:02
1997    13/09/2023 09:02
1998    13/09/2023 09:03
1999    13/09/2023 09:03
2000    13/09/2023 09:07
2001    13/09/2023 09:07
2002    13/09/2023 09:08
2003    13/09/2023 09:08
2004    13/09/2023 09:08
2005    13/09/2023 09:09
2006    13/09/2023 09:09
2007    13/09/2023 09:11
hmae6n7t

hmae6n7t1#

Change date format for your session to day-month-year before running bulk insert:

SET DATEFORMAT DMY;

相关问题