Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.3k views
in Technique[技术] by (71.8m points)

csv - How to insert DD/MM/YYYY into SQL Server DATE format?

I'm trying to bulk insert a csv file and have columns which include dates that are in the DD/MM/YYYY format when the sql DATE format is YYYY-MM-DD and some are even D/M/YYYY as it isn't 01/01/2020 instead it is 1/1/2020 so I don't think I can slice the string.

csv table


BULK INSERT orders
    FROM 'C:Orders.csv'
    WITH
    (
    FIRSTROW = 2,
    FIELDTERMINATOR = ',',  --CSV field delimiter
    ROWTERMINATOR = '
',   --Use to shift the control to next row
    ERRORFILE = 'C:OrdersErrorRows.csv',
    TABLOCK
    );
question from:https://stackoverflow.com/questions/65949303/how-to-insert-dd-mm-yyyy-into-sql-server-date-format

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

You can convert to date and specify the format. Try the syntax referenced:

https://www.mssqltips.com/sqlservertip/1145/date-and-time-conversions-using-sql-server/


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...