There are three ways to avoid the "Division by zero encountered" error in your SELECT statement and these are as follows:
Using the CASE statement, your query will look like the following:
SELECT CASE WHEN [Denominator] = 0 THEN 0 ELSE [Numerator] / [Denominator] END AS [Percentage] FROM [Table1]
If the denominator or divisor is 0, the result becomes 0. Otherwise, the division operation is performed.
Using the NULLIF and ISNULL functions, your query will look like the following:
SELECT ISNULL([Numerator] / NULLIF([Denominator], 0), 0) AS [Percentage] FROM [Table1]
Lastly, using the SET ARITHABORT and SET ANSI_WARNINGS, your query will look like the following:
SET ARITHABORT OFF SET ANSI_WARNINGS OFF SELECT [Numerator] / [Denominator]
SET ARITHABORT OFF SET ANSI_WARNINGS OFF SELECT ISNULL([Numerator] / [Denominator], 0)