0

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"?

9
Contributors
10
Replies
11
Views
12 Years
Discussion Span
Last Post by peter_budo
0

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

0

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
0

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.

0

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

0

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...

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.