SQL Query - Divide by Zero

What am I doing wrong when I design queries like this one and it give me a DIVIDE BY ZERO error!

SELECT     TOP 100 PERCENT FIRSTNAME, LASTNAME, RUSHES, GAMESPLAYED, RUSHES / GAMESPLAYED AS RUSHESPERGAME, TEAMCODE,
                      PLAYERID
FROM         dbo.NFL_SEC3_PRECORD
ORDER BY RUSHES / GAMESPLAYED DESC

Can someone also tell me how to fix this query...

JS
LVL 3
jsuttorAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

raterusCommented:
GAMESPLAYED has to = 0 at some point in your data.  You may want to change your query to filter out the data when GAMESPLAYED=0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
DabasCommented:

SELECT     TOP 100 PERCENT FIRSTNAME, LASTNAME, RUSHES, GAMESPLAYED, Case GamesPlayed when 0 then 0 else RUSHES / GAMESPLAYED end AS RUSHESPERGAME, TEAMCODE,
                      PLAYERID
FROM         dbo.NFL_SEC3_PRECORD
ORDER BY case gamesplayed when 0 then 0 else RUSHES / GAMESPLAYED end DESC
DabasCommented:
Correction:

SELECT     TOP 100 PERCENT FIRSTNAME, LASTNAME, RUSHES, GAMESPLAYED, RushesPerGame = Case GamesPlayed when 0 then 0 else RUSHES / GAMESPLAYED end , TEAMCODE,
                      PLAYERID
FROM         dbo.NFL_SEC3_PRECORD
ORDER BY case gamesplayed when 0 then 0 else RUSHES / GAMESPLAYED end DESC
Your Guide to Achieving IT Business Success

The IT Service Excellence Tool Kit has best practices to keep your clients happy and business booming. Inside, you’ll find everything you need to increase client satisfaction and retention, become more competitive, and increase your overall success.

raterusCommented:
Dabas had some very good input into this question, in fact a complete solution (maybe not yours though).  If you ended up using some of the suggestion, I would have preferred a split here.
DabasCommented:
raterus:
Thanks.

I think jsuttor accepted your solution before he got to read mine. Yours is simpler too, in case he does not want to display the cases where GamesPlayed = 0
If GamesPlayed = 0 is of importance, then he should use mine.

Dabas
jsuttorAuthor Commented:
Dabas I actually read the first answer and found my answer before and gave out points before I actually received the email that you had responded to the questions. Looking at it now I would have split the points.
jsuttorAuthor Commented:
Thanks!
DabasCommented:
Thanks to both of you
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft SQL Server

From novice to tech pro — start learning today.