[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

truncation error in sybase ?

Posted on 2004-11-02
4
Medium Priority
?
7,152 Views
Last Modified: 2010-10-05
hello experts,

I get truncation error when i try to do the following

set nocount on
declare @var1 int,
        @var2 int,
        @var3 numeric(10,2)
       
       
select @var1 = 5
select @var2 = 6

select @var3 = @var1/@var2

select @var3

go

I get a 0 in @var3 and a trucation error occured ..

basically i want to do a @var1/@var2 * 100 (to find out the % )

how can this be done ?

thanks
0
Comment
Question by:Sadagopank
[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
  • 2
4 Comments
 
LVL 14

Accepted Solution

by:
Jan Franek earned 150 total points
ID: 12474330
You need to convert @var1 to some more precise numeric type (eg. numeric(10,2) ) to get rid of 0 and convert whole expresion to the same type to get rid of truncation error:

select @var3 = convert(numeric(10,2),convert(numeric(10,2),@var1)/@var2)

0
 
LVL 14

Expert Comment

by:Jan Franek
ID: 12474338
Other way how to get rid of truncation error:

set arithabort numeric_truncation off
select @var3 = convert(numeric(10,2),@var1)/@var2
set arithabort numeric_truncation on
0
 
LVL 24

Expert Comment

by:Joe Woodhouse
ID: 12478899
Even more simply:

select @var3 = 1.0*@var1/@var2

There is a hierarchy of datatypes. When the expression is just "@var1/@var2", Sybase sees only integers, and assumes you want integer division. By adding the 1.0 at the start of the expression, Sybase understands you're talking about numerics (as numerics take precedence over integers, so the entire expression is "promoted" to a numeric).
0
 

Author Comment

by:Sadagopank
ID: 12479557
thanks jan and joe ... the solution worked just fine.

0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

An overview of cyber security, cyber crime, and personal protection against hackers. Includes a brief summary of the Equifax breach and why everyone should be aware of it. Other subjects include: how cyber security has failed to advance with technol…
Are you looking for the options available for exporting EDB files to PST? You may be confused as they are different in different Exchange versions. Here, I will discuss some options available.
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…

656 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