0

I have this query executing in client side

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

Now the @id value is 2147483647 and I'm getting this error:

com.microsoft.

I tried to cast and convert like below

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

but no luck.

Is there a way to cast/convert the addition into bigint in the where condition?

Thanks

3
  • Column orderid data type? Commented Mar 30, 2021 at 14:57
  • 1
    Apparently you need to change the data type of the variable @id to bigint. But I think that you also can do like this cast(@id as bigint) + 1000 Commented Mar 30, 2021 at 14:59
  • bigint. orderid has 2148504713 in orders table. Commented Mar 30, 2021 at 15:00

1 Answer 1

3

Cast before adding:

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

Or better yet, declare @id to be a bigint.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.