user5037717
user5037717

Reputation: 37

Teradata keeps returning zeros for decimals

Casting as decimal with precision 2, keeps returning 00 after the decimal. How do I actually return values?

column1 hourlycolumn1

---------- ------------------

9797 163.00

358 5.00

265 4.00

    select top 10

column1,cast(column1/60 as decimal(6,2)) as "hourlycolumn1"

from 

....

What I would like to return is below

column1 hourlycolumn1

---------- ------------------

9797 163.28

358 5.96

265 4.41

Upvotes: 2

Views: 12635

Answers (1)

dnoeth
dnoeth

Reputation: 60472

Your column is an Integer and Integer-division truncates. The cast to decimal is after truncation.

Simply cast before division

column1,cast(column1 as decimal(6,2))/60

Calculations based on Decimals are a bit tricky in Teradata because it's rounded after every step, thus a basic recommendation is to to multiplication before division. See DECIMAL Result Data Type

Upvotes: 5

Related Questions