Hi All,

When I run the query:

select (100/50)

It give me "2"... good.

But when I run the query:

select (50/100)

I was expected it will give me 0.5... but it gives me 0 instead? Why? and How can I get the "0.5"?

change the resulting variable to type double

im not too familiar with sql but i would assume it has something to do with data types maybe? for example if it was integer it would only return a whole number such as 2 or 0 in your case, im not too sure about this in sql as i dont do it but generally that could be the problem

try doing your calculations before your sql statment

Dim i As Double
Dim MySql as string 
i = 50 / 100
Mysql="Select " & i & " FROM table;"
rs.open MySQl,conn,3,3,1

or simply "select 50. / 100"

It will work fine as long as one of the numbers in division is a float or similar.
Try

select (cast(50 as float)/100)

This will work with any numeric data.

oops wujtehacjusz, you may have a look at issue date;)

oops wujtehacjusz, you may have a look at issue date;)

Damn you are right... :P

the integer division is done. so the result is in integer.
try select convert(numeric(5,2), 50)/100 OR
select 50.00/100.00

the integer division is done. so the result is in integer.
try select convert(numeric(5,2), 50)/100 OR
select 50.00/100.00

Another genius...