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

Re: How to get the result for smaller number divide larger number? 80 80

change the resulting variable to type double

Re: How to get the result for smaller number divide larger number? 80 80

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

Re: How to get the result for smaller number divide larger number? 80 80

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
Re: How to get the result for smaller number divide larger number? 80 80

Hi,

Try "select (50 * 1.0/100)" instead of "select (50/100)"

Eralper
http://www.kodyaz.com

Re: How to get the result for smaller number divide larger number? 80 80

or simply "select 50. / 100"

Re: How to get the result for smaller number divide larger number? 80 80

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.

Re: How to get the result for smaller number divide larger number? 80 80

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

Re: How to get the result for smaller number divide larger number? 80 80

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

Damn you are right... :P

Re: How to get the result for smaller number divide larger number? 80 80

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

Re: How to get the result for smaller number divide larger number? 80 80

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.18 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.