首页 > 解决方案 > SQL Server:在where条件下将表达式转换为数据类型int的算术溢出错误

问题描述

我在客户端执行此查询

select * 
from orders 
where orderid > @id and orderid < @id + 1000 

现在@id值是 2147483647,我收到了这个错误:

com.microsoft。

我试图像下面那样投射和转换

select * 
from orders 
where orderid > @id and orderid < cast(@id + 1000 as bigint)

但没有运气。

有没有办法将加法转换/转换成bigint条件where

谢谢

标签: sqlsql-servertsql

解决方案


添加前投射:

select *
from orders
where orderid > @id and orderid < cast(@id as bigint) + 1000 ;

或者更好的是,声明@idbigint.


推荐阅读