How to Replace NULL with ZERO in SQL Syntax

Posted: 10th December 2008 by marc in Programming
Comments Off


For whatever reason I didn’t recall this function existed, and so I searched Google for convert NULL to ZERO.  I was amazed that it wasn’t easy to spot it, and at how many people didn’t provide this as the correct answer.  Instead they gave ways to program around it…

You can use the ISNULL in your SQL syntax to convert null to another specified value.  It replaces NULL with any specified replacement value assuming it is the correct type, otherwise it just uses the value of the field.
 
Syntax:
 
ISNULL (check_expression , replacement_value )
 
Example:
 
SELECT a.ProductName, ISNULL(a.RegularPrice, 0), ISNULL(a.SalePrice, 0), (ISNULL(a.RegularPrice,0) – ISNULL(c.SalePrice,0)) AS DollarsOffPrice
FROM @temp_exp a
 
More Information
  • http://www.esoftcoder.com mike

    Thanks good example

blog comments powered by Disqus