Free Information Technology Magazines and eBooks

Saturday, July 04, 2009

How to return empty string instead of Null in T-SQL

Inside .NET applications, you can anticipate null field values by using the IsDBNull function or by checking if it is equal to DBNull.Value. But you can avoid this extra coding by using ISNULL function on your T-SQL query. Here is an example.

The following query will select cellphone column from the table and return blank strings if it contains NULL value.


SELECT ISNULL(cellphone,'') FROM Customers


Using this code technique will eliminate extra coding and you are sure that your query wont return any null values.

For more SQL coding tips, subscribe now.

0 comments: