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)
 Update help

Author  Topic 

sparrow
Starting Member

20 Posts

Posted - 2008-08-27 : 18:56:08
I have the following statement

UPDATE Programme SET fSTMValue =
( fCredit / ( fDuration / 12 ) ) FROM Programme

Which when run returns the following error

Msg 8134, Level 16, State 1, Line 1
Divide by zero error encountered.

There are no zeros in either the fcredit or fDuration columns

I have run the statement
UPDATE Programme SET fSTMValue =
( fCredit / fDuration ) FROM Programme

Which runs fine

Any ideas?

Cheers


tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2008-08-27 : 19:11:49
You probably want:

(fCredit/(fDuration/12.0))

so that fDuration/12 has decimals and doesn't round to a whole number.


Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

sparrow
Starting Member

20 Posts

Posted - 2008-08-27 : 19:17:02
Thats the one

Thanks
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2008-08-28 : 02:25:40
Also see http://sqlblogcasts.com/blogs/madhivanan/archive/2008/01/16/beware-of-implicit-conversions.aspx

Madhivanan

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

- Advertisement -