Home » SQL & PL/SQL » SQL & PL/SQL » second case issue
second case issue [message #195208] Wed, 27 September 2006 07:02 Go to next message
steffeli
Messages: 112
Registered: July 2006
Senior Member
Hello

how can I prevent an error division by 0?

I calculate a param in my select statement, where a and b stands for calculation (several rows)

select  a/b as param



I could write

select  case when b <> 0
             then a/b
             else null
        end as param


but the issue is, that I have to write b (which is several rows) twice. Is there a better solution to prevent division by 0?

Thanks
Stefan
Re: second case issue [message #195308 is a reply to message #195208] Wed, 27 September 2006 20:03 Go to previous messageGo to next message
rleishman
Messages: 3728
Registered: October 2005
Location: Melbourne, Australia
Senior Member
SELECT a/nullif(b,0)


Ross Leishman
Re: second case issue [message #195386 is a reply to message #195308] Thu, 28 September 2006 06:05 Go to previous messageGo to next message
Frank
Messages: 7901
Registered: March 2000
Senior Member
ah, those little gems you keep forgetting about!
Re: second case issue [message #195395 is a reply to message #195386] Thu, 28 September 2006 06:49 Go to previous message
JRowbottom
Messages: 5933
Registered: June 2006
Location: Sunny North Yorkshire, ho...
Senior Member
Ditto.
Learning experience - check.
Previous Topic: retrieving values from objects
Next Topic: Working with elements in a concatenated field
Goto Forum:
  


Current Time: Thu Dec 12 04:44:40 CST 2024