User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the MS SQL section within the Web Development category of DaniWeb, a massive community of 426,450 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,347 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our MS SQL advertiser: Programming Forums
Views: 8069 | Replies: 10 | Solved
Reply
Join Date: Jun 2005
Posts: 1
Reputation: 330m is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
330m 330m is offline Offline
Newbie Poster

How to get the result for smaller number divide larger number?

  #1  
Jun 10th, 2005
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"?
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Jun 2005
Location: Texas
Posts: 120
Reputation: jwshepherd is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 5
jwshepherd's Avatar
jwshepherd jwshepherd is offline Offline
Junior Poster

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

  #2  
Jun 16th, 2005
change the resulting variable to type double
Reply With Quote  
Join Date: Aug 2005
Location: Seaham, UK
Posts: 187
Reputation: bops is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 3
bops bops is offline Offline
Junior Poster

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

  #3  
Aug 16th, 2005
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
Reply With Quote  
Join Date: Jun 2005
Location: Texas
Posts: 120
Reputation: jwshepherd is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 5
jwshepherd's Avatar
jwshepherd jwshepherd is offline Offline
Junior Poster

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

  #4  
Aug 16th, 2005
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
.: We may acquire liberty, but it is never recovered if it is lost :.
irc://irc.rizon.net/#itf
Reply With Quote  
Join Date: Aug 2005
Posts: 6
Reputation: eralper is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 2
eralper eralper is offline Offline
Newbie Poster

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

  #5  
Aug 16th, 2005
Hi,

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

Eralper
http://www.kodyaz.com
Reply With Quote  
Join Date: Jul 2005
Location: Dallas, TX
Posts: 481
Reputation: campkev is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 19
campkev campkev is offline Offline
Posting Pro in Training

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

  #6  
Nov 1st, 2005
or simply "select 50. / 100"
Reply With Quote  
Join Date: Mar 2007
Posts: 18
Reputation: wujtehacjusz is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 7
wujtehacjusz's Avatar
wujtehacjusz wujtehacjusz is offline Offline
Newbie Poster

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

  #7  
Jun 6th, 2008
It will work fine as long as one of the numbers in division is a float or similar.
Try
  1. SELECT (cast(50 AS float)/100)
This will work with any numeric data.
Reply With Quote  
Join Date: Apr 2008
Posts: 295
Reputation: tesuji is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 41
tesuji tesuji is offline Offline
Posting Whiz in Training

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

  #8  
Jun 7th, 2008
oops wujtehacjusz, you may have a look at issue date
Reply With Quote  
Join Date: Mar 2007
Posts: 18
Reputation: wujtehacjusz is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 7
wujtehacjusz's Avatar
wujtehacjusz wujtehacjusz is offline Offline
Newbie Poster

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

  #9  
Jun 9th, 2008
Originally Posted by tesuji View Post
oops wujtehacjusz, you may have a look at issue date

Damn you are right...
Reply With Quote  
Join Date: Aug 2006
Location: New Jersey
Posts: 3
Reputation: sujendra is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 1
sujendra's Avatar
sujendra sujendra is offline Offline
Newbie Poster

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

  #10  
Jun 16th, 2008
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
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb MS SQL Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the MS SQL Forum

All times are GMT -4. The time now is 3:11 pm.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC