Solved

multiplication in ssms gives error

Posted on 2011-09-19
4
286 Views
Last Modified: 2012-05-12
select 5494516 * 8192 gives Arithmetic overflow error converting expression to data type int. why- is there limit?
0
Comment
Question by:25112
4 Comments
 
LVL 13

Accepted Solution

by:
LIONKING earned 167 total points
ID: 36561069
Becuase since you don't specify the datatype of either value, SQL Server assumes they're both integers, therefore the result is also an integer. Since the value exceeds the maximum value for an int datatype, it throws an overflow exception.

What you can do is to cast one of the values (or both) to a datatype that can hold a bigger value (i.e. float).

I tried this and it worked.

select cast(5494516 as float) * cast(8192 as float)
0
 
LVL 11

Assisted Solution

by:rajvja
rajvja earned 166 total points
ID: 36561160
Hi

select 5494516 * 8192.0

this is sufficient
0
 
LVL 75

Assisted Solution

by:Anthony Perkins
Anthony Perkins earned 167 total points
ID: 36561703
I would not use float, as after all it is an aproximate data type. Instead use bigint, as in (fix the obvious typo in xSELECT and xCAST):
xSELECT  xCAST(5494516 AS bigint) * 8192
0
 
LVL 5

Author Comment

by:25112
ID: 36562229
perfect..
0

Featured Post

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
The Delta outage: 650 cancelled flights, more than 1200 delayed flights, thousands of frustrated customers, tens of millions of dollars in damages – plus untold reputational damage to one of the world’s most trusted airlines. All due to a catastroph…
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.

726 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question