TRY_CONVERT 在 SQL Server 2012 上失败 [英] TRY_CONVERT fails on SQL Server 2012

查看:33
本文介绍了TRY_CONVERT 在 SQL Server 2012 上失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下 SQL 语句在 SQL Server 2012(SP1) 11.0.3401.0 版本上失败

The following SQL statement fails on SQL Server 2012(SP1) 11.0.3401.0 Version

DECLARE @b VARCHAR(10) = '12312.2'
SELECT TRY_CONVERT(DECIMAL(10,2),@b)

错误信息

Msg 195, Level 15, State 10, Line 2
'DECIMAL' is not a recognized built-in function name.

但在 SQL Server 2012(SP1) 11.0.3393.0 上运行良好

But works fine on SQL Server 2012(SP1) 11.0.3393.0

两个服务器都没有问题 TRY_PARSE()

Both servers have no problem with TRY_PARSE()

DECLARE @b VARCHAR(10) = '12312.2'
SELECT TRY_PARSE(@b AS DECIMAL(10,2))

更新:

在进一步测试并尝试转换为不同类型后得到另一个不同的错误消息

after further testing and trying conversion to different types got another different error message

DECLARE @b VARCHAR(10) = '12312'
SELECT TRY_CONVERT(INT,@b)

错误:

error: Msg 195, Level 15, State 10, Line 2
'TRY_CONVERT' is not a recognized built-in function name.

原来的错误信息是错误的,但现在我更困惑为什么它不存在.

So original error message was miss leading, but now I'm even more confused why it is not there.

推荐答案

检查您正在使用该函数的特定数据库的数据库兼容性级别是否设置为 SQL Server 2012 (110) 下数据库的属性/选项/兼容性级别.

Check that the database compatibility level for the particular database you are using the function in is set to SQL Server 2012 (110) under properties/options/compatibility level for the database.

这篇关于TRY_CONVERT 在 SQL Server 2012 上失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆