sql - SQL Server:在where条件下将表达式转换为数据类型int的算术溢出错误
问题描述
我在客户端执行此查询
select *
from orders
where orderid > @id and orderid < @id + 1000
现在@id
值是 2147483647,我收到了这个错误:
我试图像下面那样投射和转换
select *
from orders
where orderid > @id and orderid < cast(@id + 1000 as bigint)
但没有运气。
有没有办法将加法转换/转换成bigint
条件where
?
谢谢
解决方案
添加前投射:
select *
from orders
where orderid > @id and orderid < cast(@id as bigint) + 1000 ;
或者更好的是,声明@id
为bigint
.
推荐阅读
- java - 使用 Apache PO API 创建 CSV 文件
- java - 数组列表的三种声明方式有什么区别,为什么要先写接口,再写实现类?
- amazon-web-services - 本地测试step函数出错:请求中包含的安全令牌无效
- android - Kotlin Multiplatform 中的单个项目中的业务和客户应用程序?
- node.js - 在 i18n-iso-countries 中找不到“变音符号”错误?
- node.js - 如何使不同的页面具有不同的网格模板行,但共享相同的模板列?
- laravel-7 - 如何在 Laravel 7 中制作具有相同 id 的多张图片
- php - 如何在php中使用用户名作为页面名称?
- mongodb - 没有使用 MongoDB Native NodeJS 驱动程序的 post 请求正文
- android - 如何在后台服务中获取其他应用程序的调试数据