Sadagopank
asked on
truncation error in sybase ?
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
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
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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).
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).
ASKER
thanks jan and joe ... the solution worked just fine.
set arithabort numeric_truncation off
select @var3 = convert(numeric(10,2),@var
set arithabort numeric_truncation on