如何更新 T-SQL 中的 DateTime 字段?

2021-09-10 00:00:00 sql types tsql sql-server

以下查询不更新日期时间字段:

The following query does not update the datetime field:

update table
SET EndDate = '2009-05-25'
WHERE Id = 1

我也试过没有破折号,但这也不起作用.

I also tried it with no dashes, but that does not work either.

推荐答案

如有疑问,明确说明使用 CAST/CONVERT 的数据类型转换:

UPDATE TABLE
   SET EndDate = CAST('2009-05-25' AS DATETIME)
 WHERE Id = 1

相关文章