1

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

user5037717
  • 35
  • 1
  • 1
  • 6
  • possible duplicate of http://stackoverflow.com/questions/3443672/integer-division-in-sql-server try converting your column1 to decimal as well – niketshah90 Aug 03 '16 at 04:07
  • The fix that involves the minimal amount of typing is to change 60 to a decimal value such as 60.0 – David Cram Aug 03 '16 at 15:42

1 Answers1

3

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

dnoeth
  • 59,503
  • 4
  • 39
  • 56