dbTalk Databases Forums  

Divide by Zero

comp.databases.ms-sqlserver comp.databases.ms-sqlserver


Discuss Divide by Zero in the comp.databases.ms-sqlserver forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Joriveek
 
Posts: n/a

Default Divide by Zero - 03-08-2006 , 08:53 AM






When I specify a formula between Computed Column Specification, I have two
zero values, getting Divide by Zero error, any idea how can I avoid this? I
still want SQL Server to display Zero if it is 0/0, is this possible in SQL
Server database?

Thanks
J.



Reply With Quote
  #2  
Old   
SQL
 
Posts: n/a

Default Re: Divide by Zero - 03-08-2006 , 08:57 AM






use case, here is an example

create table #test (value1 numeric (12,2),value2 numeric (12,2))
insert into #test
select 1,0 union all
select 1,0 union all
select 5,3 union all
select 4,2
select case value2 when 0 then 0 else value1/value2 end as SomeValue
from #test

http://sqlservercode.blogspot.com/


Reply With Quote
  #3  
Old   
yangyang
 
Posts: n/a

Default Re: Divide by Zero - 03-08-2006 , 10:22 AM



IF like this:
Update a
Set X=column b/column c
where Column c<>0

Update a
Set X=0
where Column c=0

any help to you?


Reply With Quote
  #4  
Old   
MC
 
Posts: n/a

Default Re: Divide by Zero - 03-09-2006 , 03:17 AM



Or perhaps something like:

Update a
Set X= case when columnc=0 then 0 else column b/column c end




MC

"yangyang" <loveflying000 (AT) gmail (DOT) com> wrote

Quote:
IF like this:
Update a
Set X=column b/column c
where Column c<>0

Update a
Set X=0
where Column c=0

any help to you?




Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.