Using T-SQL to Avoid Unwanted NULLs

Here's how to use the IsNULL() function in T-SQL to avoid returning NULL values from your queries.

William Vaughn

January 21, 2003

1 Min Read
ITPro Today logo in a gray background | ITPro Today


You can avoid returning NULL values from your queries by using the IsNULL() function in your T-SQL query or stored procedure, as the code in Listing A shows. This way, if a column contains a NULL, the server substitutes either a string or another specified value (the data types must match). In Listing A's code, for example, I return -1 as a substitute for any NULLs encountered in the Year_Born column data.

Sign up for the ITPro Today newsletter
Stay on top of the IT universe with commentary, news analysis, how-to's, and tips delivered to your inbox daily.

You May Also Like