I'm not terribly sure what I should do to combat this situation, and hoped I could find an answer here.
I've got this type of SELECT QUERY already using a CASE WHEN construction for a basic summary query. It works GREAT for everything else, but I need to use a different construction for this, or else add something to the CASE WHEN statment, I suppose, in this scnerio.
Here's the SQL Code:
The problem is when there are Original Balances (OrigBal) that are $0. That's throwing me the following error:
Is there any quick, simple, easy way to combat this? Do I need to somehow strip the $0 origBal records out to begin with? Any thoughts/suggestions?
--
"If to err is human, then I must be some kind of human!" -Me
I've got this type of SELECT QUERY already using a CASE WHEN construction for a basic summary query. It works GREAT for everything else, but I need to use a different construction for this, or else add something to the CASE WHEN statment, I suppose, in this scnerio.
Here's the SQL Code:
Code:
SELECT
SUM(CASE WHEN CurrBal / OrigBal <= .1 THEN 1 ELSE 0 END) AS [<11%]
,SUM(CASE WHEN CurrBal / OrigBal BETWEEN .1 AND .2 THEN 1 ELSE 0 END) AS [11% - 20%]
,SUM(CASE WHEN CurrBal / OrigBal BETWEEN .21 AND .3 THEN 1 ELSE 0 END) AS [21% - 30%]
,SUM(CASE WHEN CurrBal / OrigBal BETWEEN .31 AND .4 THEN 1 ELSE 0 END) AS [31% - 40%]
,SUM(CASE WHEN CurrBal / OrigBal BETWEEN .41 AND .5 THEN 1 ELSE 0 END) AS [41% - 50%]
,SUM(CASE WHEN CurrBal / OrigBal > .51 THEN 1 ELSE 0 END) AS [>51%]
FROM MyTable
The problem is when there are Original Balances (OrigBal) that are $0. That's throwing me the following error:
SQL said:Msg 8134.... Divide by zero error encountered.
Is there any quick, simple, easy way to combat this? Do I need to somehow strip the $0 origBal records out to begin with? Any thoughts/suggestions?
--
"If to err is human, then I must be some kind of human!" -Me