Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 SQL help, divide by 0

Author  Topic 

jrockfl
Posting Yak Master

223 Posts

Posted - 2004-10-21 : 10:40:01
In one of my rows cost and sales are both equal to 0, so the query returns an error. What can I do to correct this?

SELECT ((cost / sales) * 100) As percentprofit
FROM squareinch

Kristen
Test

22859 Posts

Posted - 2004-10-21 : 10:52:53
SELECT CASE WHEN COALESCE(sales, 0) = 0 THEN NULL ELSE ((cost / sales) * 100) END As percentprofit
FROM squareinch

Krsiten
Go to Top of Page

jrockfl
Posting Yak Master

223 Posts

Posted - 2004-10-21 : 11:16:56
Perfect! Thank you!!
Go to Top of Page
   

- Advertisement -