I have a view in SQL Server 2008 with several columns that are expressions of one column divided by another. I have to account for the divisor being 0, so I use a CASE statement. Here is an example of one:
CASE SUM(dbo.GameStats.BringBacksAttempted)
WHEN 0 THEN
0
ELSE
SUM(dbo.GameStats.BringBacks) / SUM(dbo.GameStats.BringBacksAttempted)
END
Even when SUM(BringBacksAttempted) and SUM(BringBacks) are not 0, the statement is always 0. What am I doing wrong?