divide by zero

longway

Member
Joined
Mar 9, 2005
Messages
6
Programming Experience
Beginner
I have a table that contains football teams, and the number of wins and losses that they have. I am ordering them by win percentage, so they are in order of first place down to last. Here is my query:

select * from nfcnorth
order by won / won + loss

The problem is when a team has no wins. this causes a division by zero, which of course causes an error. what can I do about this?
 
It doesw work, I use that kind of a construct all the time.

as long as it's SQL Server..... I can't vouch for any other DBMS.

-tg
 
Actually it is kind of math trick ... i made some simple test and i came to this

VB.NET:
[size=2][color=#0000ff]Dim[/color][/size][size=2] wins [/size][size=2][color=#0000ff]As[/color][/size][size=2][color=#0000ff]Double[/color][/size][size=2] = Val(txt1.text)
 
[/size][size=2][color=#0000ff]Dim[/color][/size][size=2] loss [/size][size=2][color=#0000ff]As[/color][/size][size=2][color=#0000ff]Double[/color][/size][size=2] = Val(txt2.Text)
 
[/size][size=2][color=#0000ff]Dim[/color][/size][size=2] result [/size][size=2][color=#0000ff]As[/color][/size][size=2][color=#0000ff]Double
 
[/color][/size][size=2][color=#0000ff]If[/color][/size][size=2] wins = 0 [/size][size=2][color=#0000ff]Then
 
[/color][/size][size=2]result = 0
 
[/size][size=2][color=#0000ff]Else
 
[/color][/size][size=2]result = wins / (wins + loss)
 
[/size][size=2][color=#0000ff]End [/color][/size][size=2][color=#0000ff]If
 
[/color][/size][size=2]MessageBox.Show(result)
[/size]
and finally you can implement as it follows:
VB.NET:
select * from nfcnorth order by result
with a difference that you should first fetch wins instead enter in textBox like i did here

Regards ;)
 
Back
Top