Divide by zero error sql <p>I get the divide by zero error using this:</p> <pre><code>Select Top 100 *, Case (a.value) When 0.0 Then Null Else ((cast(b.value as decimal) - cast(a.value as decimal))/cast(a.value as decimal)) * 100 End as 'Montly Price Change (%)' From AllProducts a Join AllProducts b On a.series_id=b.series_id And (b.Date = DATEADD(month, 1, a.Date)) </code></pre> <p>I can't find a way to fix it.. I've tried </p> <pre><code>Select Top 100 *, Case cast((a.value) as decimal) When 0.0 Then Null Else ((cast(b.value as decimal) - cast(a.value as decimal))/cast(a.value as decimal)) * 100 End as 'Montly Price Change (%)' From AllProducts a Join AllProducts b On a.series_id=b.series_id And (b.Date = DATEADD(month, 1, a.Date)) </code></pre> <p>but this makes my entire column null for some reason..</p>