Tuesday, March 30, 2010

SQL Coalesce

If you want to convert null fields into something else inside your select command, you can do that with "Coalesce".

select

custid, coalesce( region, ' ')  as region
from Sales.Customers
order by region;

This SQL query will show null regions as space.

1 comment:

  1. You can also use ISNULL() in the same way. For example, select ISNULL(region, 'none') as region from Customers

    ReplyDelete

Hey!
Let me know what you think?