Solved

multiplication in ssms gives error

Posted on 2011-09-19
4
287 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

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…
Recently we ran in to an issue while running some SQL jobs where we were trying to process the cubes.  We got an error saying failure stating 'NT SERVICE\SQLSERVERAGENT does not have access to Analysis Services. So this is a way to automate that wit…
Via a live example, show how to backup a database, simulate a failure backup the tail of the database transaction log and perform the restore.
Viewers will learn how to use the UPDATE and DELETE statements to change or remove existing data from their tables. Make a table: Update a specific column given a specific row using the UPDATE statement: Remove a set of values using the DELETE s…

695 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