Solved

multiplication in ssms gives error

Posted on 2011-09-19
4
284 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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Trying to get a Linked Server to Oracle DB working 21 59
TSQL query to generate xml 4 33
SQL Improvement  ( Speed) 14 27
Find results from sql within a time span 11 30
Why is this different from all of the other step by step guides?  Because I make a living as a DBA and not as a writer and I lived through this experience. Defining the name: When I talk to people they say different names on this subject stuff l…
Composite queries are used to retrieve the results from joining multiple queries after applying any filters. UNION, INTERSECT, MINUS, and UNION ALL are some of the operators used to get certain desired results.​
Using examples as well as descriptions, and references to Books Online, show the documentation available for date manipulation functions and by using a select few of these functions, show how date based data can be manipulated with these functions.
Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.

776 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