Solved

truncation error in sybase ?

Posted on 2004-11-02
6,279 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
Question by:Sadagopank
    4 Comments
     
    LVL 14

    Accepted Solution

    by:
    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
    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
    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
    thanks jan and joe ... the solution worked just fine.

    0

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Looking for New Ways to Advertise?

    Engage with tech pros in our community with native advertising, as a Vendor Expert, and more.

    Every business owner understands the significance of online customer reviews and the impact it can have on sales and revenues. With technology advancing at such a rapid pace, getting online reviews has never been easier, especially when many regions…
    With the shift in today’s hiring climate (http://blog.experts-exchange.com/ee-blog/5-tips-on-succeeding-in-the-new-gig-economy/?cid=Blog_031816), many companies are choosing to hire freelancers to get projects completed efficiently and inexpensively…
    This video Micro Tutorial is the second in a two-part series that shows how to create and use custom scanning profiles in Nuance's PaperPort 14.5 (http://www.experts-exchange.com/articles/17490/). But the ability to create custom scanning profiles a…
    Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

    846 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

    Need Help in Real-Time?

    Connect with top rated Experts

    7 Experts available now in Live!

    Get 1:1 Help Now