Using NULLIF() To Prevent Divide-By-Zero Errors In SQL

<!---
	Do SQL division with divide-by-zero protection. But this,
	time, let's provide a default value if the division is
	not valid.
--->
<cfquery name="qDivision" datasource="#REQUEST.DSN.Source#">
	SELECT
		(
			ISNULL(
				(45 / NULLIF( 0, 0 )),
				0
			)
		) AS value
	;
</cfquery>
 
<!--- Output resulting value. --->
[ #qDivision.value# ]

For Cut-and-Paste