用户登录
用户注册

分享至

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

  • 作者: 逗比男神你建哥
  • 来源: 51数据库
  • 2022-10-20

问题描述

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

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
软件
前端设计
程序设计
Java相关