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
 Transact-SQL (2000)
 Divide by zero error encountered in update

Author  Topic 

rookie_sql
Constraint Violating Yak Guru

443 Posts

Posted - 2007-08-02 : 03:25:57
Hi i get a divide by zero when i try and calculate percentages in an update.. i tried using the ISNULL but am still getting the error.


Update tbl_test
SET [%DisSatisfaction] = ( DisSatisfied / Number_S * 100.0 )

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2007-08-02 : 03:57:14
Update tbl_test
SET [%DisSatisfaction] = case when number_s is null or number_s = 0 then 0 else ( DisSatisfied / Number_S * 100.0 ) end




E 12°55'05.25"
N 56°04'39.16"
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2007-08-02 : 04:18:20
Also it is better to avoid special characters as part of object names. DisSatisfaction_percent would be best option

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

PSamsig
Constraint Violating Yak Guru

384 Posts

Posted - 2007-08-10 : 02:21:21
Hmmm, isn't it overkill to check for NULL? And wouldn´t a more correct result be NULL if there ain't any samles?

-- If you give someone a program, you will frustrate them for a day; if you teach them how to program, you will frustrate them for a lifetime.
Go to Top of Page
   

- Advertisement -