For SQL Server 2008 R2, is it possible to import a .csv file with a date in “MM/DD/YYYY” format, using “bulk insert”? Or do I have to alter my .csv file to have a format that SQL Server 2008 R2 expects?
I execute the following in Microsoft SQL Server 2008 R2:
BULK
INSERT dbo.TCsvOptionContracts
FROM 'C:\x.csv'
WITH
(
FIELDTERMINATOR = ',',
ROWTERMINATOR = '\n',
FORMATFILE = 'C:\format.xml',
FIRSTROW = 2
)
GO
And I get this error:
Bulk load data conversion error (type mismatch or invalid character for the specified codepage) for row 2, column 1 (Date).
The date in this column of the .csv file is in the form MM/DD/YYYY, i.e. “02/16/2011”.
p.s. I generated a format file with the following command, however, I didn’t see any option to specify the MM/DD/YYYY date format for the offending column:
bcp Engine..TCsvOptionContracts format nul -c -x -f C:\format.xml -t, -T
Configured the “date” column to be “smalldatetime” instead of “datetime”. Tried it, and everything imported 100%.
There are two potential methods to do this: