There are times when we want to return empty strings for column(s) which have NULL values. T-SQL makes this easy with ISNULL function. Two parameters for this function are:

  1. The column in question
  2. Replacement value

 

Here is an example query for Customers table in Northwind database. This query will select Region column from the table and return blank strings where it finds NULL.

SELECT ISNULL(Region,'') FROM Customers

 

Here is a partial screenshot of the resultset returned. You can see that the value for top rows is blank. These are actually NULL in database.

image

Tagged with:
 

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>