[dba-SQLServer] Div Zero problem

Doris Manning mikedorism at verizon.net
Tue Aug 5 10:26:51 CDT 2008


CASE WHEN b = 0 THEN a ELSE a/b END

Doris Manning
Database Administrator
Hargrove Inc.

-----Original Message-----
From: dba-sqlserver-bounces at databaseadvisors.com
[mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of Arthur
Fuller
Sent: Tuesday, August 05, 2008 10:58 AM
To: Discussion concerning MS SQL Server
Subject: [dba-SQLServer] Div Zero problem

I'm running into a problem where the sum of one column (call it B) could be
zero and then we want to divide column A's value by Sum(B), and if Sum(B) =
0, then I just want the value of A.

i.e.

a = 480
Sum(b) = 0  -- they are zeroes not nulls
result = a/b but with some sort of divZero function that returns a in the
event that b = zero. IOW if b = zero then b = 1.

I can write a UDF if necessary but my feeling is that this already exists in
MS SQL, I just can't put my finger on it.

Arthur
_______________________________________________
dba-SQLServer mailing list
dba-SQLServer at databaseadvisors.com
http://databaseadvisors.com/mailman/listinfo/dba-sqlserver
http://www.databaseadvisors.com






More information about the dba-SQLServer mailing list