sql - SQL Server 转换在不同服务器上失败
问题描述
我有一个 select 语句,它的Isnumeric
转换在一台服务器上失败并在另一台服务器上运行良好。
两台服务器都使用 SQL Server 2012。数据库是第二台服务器上的副本。
错误:
将 varchar 值“700.00”转换为数据类型 int 时转换失败
主选择实际上不返回任何行。
voidOrDenied = (case when isnumeric(c.reasonpending) = 1 and
cast(left(c.reasonpending, charindex(',', c.reasonpending+',')-1) as int)
between 1 and 25 then 'Void'
when c.reasonpending like '%void%' then 'Void'
else 'Denied' end),
第二台服务器上可能有什么不同?
解决方案
使用try_cast()
:
(case when try_cast(left(c.reasonpending, charindex(',', c.reasonpending+',')-1) as int) between 1 and 25
then 'Void'
when c.reasonpending like '%void%' then 'Void'
else 'Denied'
end)
推荐阅读
- r - 如何随机抽样数据框中存在的所有列?
- java - 如何在 messageDialog 中打印数组对象并每 5 个对象添加一个新行#java
- numpy - 将矩阵扩展为张量
- c# - Unity C# 嵌套 IEnumerator
- javascript - 随机 HTML 页面脚本在边缘而不是 chrome 上工作
- javascript - 使用 jquery 对复选框列表进行验证
- postgresql - Column() 得到了一个意外的关键字参数“primary_key”
- ruby - Ruby 2.1.5p273 与内存增长/泄漏的时间比较?
- rest - 在不更改代码的情况下模拟休息服务响应的方法是什么
- http - 你如何在根目录下提供静态页面,同时仍然支持 Go 中的动态路由?