Conversion failed when converting date and/or time from character string in SQL SERVER 2008(从 SQL SERVER 2008 中的字符串转换日期和/或时间时转换失败)
问题描述
我有下面的 SQL.
UPDATE student_queues
SET Deleted=0,
last_accessed_by='raja',
last_accessed_on=CONVERT(VARCHAR(24),'23-07-2014 09:37:00',113)
WHERE std_id IN ('2144-384-11564')
AND reject_details='REJECT'
当我运行上述 SQL 时,抛出了以下异常.
when I ran the above SQL the below exception has been throwed.
从字符串转换日期和/或时间时转换失败.
推荐答案
如果您尝试插入 last_accessed_on,这是一个 DateTime2,那么您的问题是因为您将其转换为 SQL 无法理解的格式的 varchar.
If you're trying to insert in to last_accessed_on, which is a DateTime2, then your issue is with the fact that you are converting it to a varchar in a format that SQL doesn't understand.
如果您将代码修改为此,它应该可以工作,请注意您的日期格式已更改为:YYYY-MM-DD hh:mm:ss:
If you modify your code to this, it should work, note the format of your date has been changed to: YYYY-MM-DD hh:mm:ss:
UPDATE student_queues
SET Deleted=0,
last_accessed_by='raja',
last_accessed_on=CONVERT(datetime2,'2014-07-23 09:37:00')
WHERE std_id IN ('2144-384-11564') AND reject_details='REJECT'
或者如果你想使用CAST,替换为:
Or if you want to use CAST, replace with:
CAST('2014-07-23 09:37:00.000' AS datetime2)
这是使用 SQL ISO 日期格式.
这篇关于从 SQL SERVER 2008 中的字符串转换日期和/或时间时转换失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:从 SQL SERVER 2008 中的字符串转换日期和/或时间时转换失败
基础教程推荐
- 表 './mysql/proc' 被标记为崩溃,应该修复 2022-01-01
- 如何在 SQL 中将 Float 转换为 Varchar 2021-01-01
- 在 MySQL 中:如何将表名作为存储过程和/或函数参数传递? 2021-01-01
- oracle区分大小写的原因? 2021-01-01
- 什么是 orradiag_<user>文件夹? 2022-01-01
- 在多列上分布任意行 2021-01-01
- 如何根据该 XML 中的值更新 SQL 中的 XML 2021-01-01
- 二进制文件到 SQL 数据库 Apache Camel 2021-01-01
- mysql选择动态行值作为列名,另一列作为值 2021-01-01
- MySQL 中的类型:BigInt(20) 与 Int(20) 2021-01-01
