将 varchar 数据类型转换为 datetime 数据类型导致值超出范围

he conversion of a varchar data type to a datetime data type resulted in an out-of-range value

我创建了一个 table dbo.CovidStats( covidId(int PK), covidDate(datetime), confirmcases(int),Death(int),country(varchar),flag(bit), totalLoss(int) )

我执行了这个查询

INSERT INTO dbo.CovidStats VALUES('27/04/2022', 5500, 10, 'USA', 1, 500000); 

我得到了这个错误:

The conversion of a varchar data type to a datetime data type resulted in an out-of-range value.
The statement has been terminated.

当我从日期中删除字符串时,我得到了默认日期 1900-01-01。在专栏中

请帮忙

您收到此错误的原因是系统默认不将 dd-mm-yyyy 识别为日期格式。

要解决这个问题,您有 2 个选择:

  1. 您可以在数据插入文件的顶部使用 set dateformat dmy

  2. 但更好的方法是使用 yyyy-mm-dd 格式。