Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

divide by zero 1

Status
Not open for further replies.

LloydDobler

Technical User
Oct 3, 2002
192
0
0
CA
Hi all, getting a divide by zero error, even with a CASE statement. Am I missing something?

CASE WHEN SUM(QuantityProduced)= 0 THEN 0 ELSE SUM((QuantityProduced - scrap) / QuantityProduced) end AS QUALITY

fields QuantityProduced and Scrap are both numeric. Using Query analyzer and SQL 2K.



"I don't want to sell anything, buy anything or process anything as a career. I don't want to sell anything bought or processed... or buy anything sold or processed... or process anything sold, bought or processed... or repair anything sold, bought or processed. You know, as a career, I don't want to do that."

 
Try this:

SUM(CASE QuantityProduced WHEN 0 THEN 0 ELSE ((QuantityProduced - scrap) / QuantityProduced)) end AS QUALITY


 
the end must be within parenthesis


SUM(CASE QuantityProduced WHEN 0 THEN 0 ELSE ((QuantityProduced - scrap) / QuantityProduced) end) AS QUALITY
 
Giddy up cmartin, thanks. Knew it was gonna be something stoooopid I did.

"I don't want to sell anything, buy anything or process anything as a career. I don't want to sell anything bought or processed... or buy anything sold or processed... or process anything sold, bought or processed... or repair anything sold, bought or processed. You know, as a career, I don't want to do that."

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top