Display Decimal in SQL

Database

Display Decimal in SQL

Hello,

I am new to Teradata. I am trying to display 5 decimal places for a calculated column called 'conv' in my query. But I get 0.00000 for all of the rows. The columns used in the calculaton don't have 0 in them. So the result shouldn't be 0's. Does anyone have any suggestions?

Here is my query:

select year_month, convert(decimal(7,5),(sum(units) / sum(clicks))) as conv from top_table
where year_month >= 200901
group by year_month

I really appreciate any input. Thank you in advance!!

2 REPLIES
Enthusiast

Re: Display Decimal in SQL

I am not an expert but I believe SQL uses the dividend (or whatever it's called) to get the precision of a divide calculation. Have you tried something like:

select year_month, sum(units) / cast(sum(clicks) as decimal(7,5)) as conv
from top_table
where year_month >= 200901
group by year_month

I hope that helps.
Enthusiast

Re: Display Decimal in SQL

Sorry, I guess my reply wasn't completely accurate. You can google precision and find many examples of your question; like the following:
http://forums.teradata.com/forum/database/automatically-rounding