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 2005 Forums
 Transact-SQL (2005)
 heeelp!!! divide by zero error

Author  Topic 

squarefish
Starting Member

28 Posts

Posted - 2010-04-21 : 11:24:37
Hi there,

I'm trying to get a percentage from 2 fields, both of which could contain a 0

I can't get the syntax correct...


ISNULL(NULLIF (hasprods, 0) * 100 / NULLIF (sales, 0), 0)

But if sales = 8 and has prods = 4 I get 400 rather than the 50 I'm after.

Can anyone point me in the right direction?

Many Thanks

Kristen
Test

22859 Posts

Posted - 2010-04-21 : 11:31:13
SELECT ISNULL(NULLIF (4, 0) * 100 / NULLIF (8, 0), 0)

gives me 50 ...
Go to Top of Page
   

- Advertisement -