## don't get the decimal value when dividing int by int

### don't get the decimal value when dividing int by int

Hello All -

I don't seem to be getting the decimal values (real number), when
dividing the int by int. For example, when I divide 18 by 12, I get 1.
When I divide 12 by 18, I get 0.

I have tried using cast and convert but none helped. I am posting my
simple selects as follows.

Using SQL 7 on Win2K. Any ideas ?

select  (convert(decimal(7,2),(18 / 12))) as pct_complete
select  cast(18 / 12 as numeric) as pct_complete
select  cast(18 / 12 as numeric (5,2)) as pct_complete
select  cast(18 / 12 as decimal (5,2)) as pct_complete

thanks..

### don't get the decimal value when dividing int by int

My SQL server is down at the moment, but I think you have to:

select cast(18 as numeric(5,2)) / cast(12 as numeric(5,2) )

In other word, cast to numeric before divide, also adjust the numeric to
precision required.

Louis

Quote:> Hello All -

> I don't seem to be getting the decimal values (real number), when
> dividing the int by int. For example, when I divide 18 by 12, I get 1.
>  When I divide 12 by 18, I get 0.

> I have tried using cast and convert but none helped. I am posting my
> simple selects as follows.

> Using SQL 7 on Win2K. Any ideas ?

> select (convert(decimal(7,2),(18 / 12))) as pct_complete
> select cast(18 / 12 as numeric) as pct_complete
> select cast(18 / 12 as numeric (5,2)) as pct_complete
> select cast(18 / 12 as decimal (5,2)) as pct_complete

> thanks..

### don't get the decimal value when dividing int by int

select 18./12. [18/12], 12./18. [12/18]

Is something like this possible?

For example I would like to get a recordset containing last ten
years. How?

The only way I found (no need to tell me that I'm stupid, I know
that) is :

select Year(SYSDATE) from dual
union
select Year(SYSDATE)-1 from dual
union
...

which is, well, next to unusable. Especialy if the range would
get bigger.

Thanks, Jenda
http://Jenda.McCann.cz (CC will be appreciated.)