带有 Msg 529 错误的 sqlserver 中的 CONVERT 问题 [英] CONVERT issue in sqlserver with Msg 529 error
本文介绍了带有 Msg 529 错误的 sqlserver 中的 CONVERT 问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
select CONVERT(datetime,value,103) from results
这个声明给了我一个错误
This statement is giving me a error
"Msg 529, Level 16, State 2, Line 1
Explicit conversion from data type text to datetime is not allowed."
VALUE 列数据类型是 RESULTS 表中的 TEXT.
VALUE column Datatype is TEXT in the RESULTS table.
我怎样才能克服上述问题.请帮忙!
How can i overcome the above problem. please help !
推荐答案
您无法从 text
转换为 datetime
您必须应用两个转换操作.
You must apply two convert operations.
第一:从文本到varchar
The first: From text to varchar
第二个:从varchar到datetime
The second: From varchar to datetime
所以你的查询将变成:
SELECT CONVERT(datetime,
CONVERT(varchar(30),value), 103)
FROM results
Plus:text
数据类型已被新版本的 Sql Server 弃用,因此我强烈建议您将数据类型 text
更改(如果可以)为 varchar(最大)
.
Plus: text
datatype is deprecated for new versions of Sql Server, so I strongly advice you to change (if you can) your datatype text
into varchar(max)
.
应用更改的 DDL 代码是:
The DDL code to apply your change is:
ALTER TABLE results ALTER COLUMN value varchar(max)
这篇关于带有 Msg 529 错误的 sqlserver 中的 CONVERT 问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文