0

I'm getting:

Msg 8115 Arithmetic overflow error converting expression to data type int error

For this query:

DECLARE @x  int     
IF EXISTS ( SELECT * FROM Y)     
  BEGIN          
    SET @x = (SELECT max(Id )  from Y)+1    
  END    
ELSE 
  BEGIN         
    SET @x = 1   
  END 

I tried to cast Id to Big int and I also tried by changing x as Big int, but still getting same error.

7
  • Can you try declare @x bigint Commented Sep 14, 2016 at 9:01
  • mysql or sql server? Commented Sep 14, 2016 at 9:02
  • I tried with @x bigint but no use Commented Sep 14, 2016 at 9:07
  • 2
    @aks Did you try using the IDENTITY(1,1) for auto increment of ID column? Commented Sep 14, 2016 at 9:07
  • Is there possibility the max(Id) is the maximum value for the bigint type? Commented Sep 14, 2016 at 9:17

2 Answers 2

1

I have tried your code nothing is wrong with it, please refer this LINK it may help you.

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

Comments

0

Check the ranges of values that can be stored within the types:

https://msdn.microsoft.com/en-us/library/ms187746(v=SQL.90).aspx

https://msdn.microsoft.com/en-us/library/ms187745.aspx

(and also check this: SQL Server BIGINT or DECIMAL(18,0) for primary key)

The ID column of the decimal type may cause problem in your case.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.