Using T-SQL to Avoid Unwanted NULLs

Downloads
37569.zip

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.

Hide comments

Comments

  • Allowed HTML tags: <em> <strong> <blockquote> <br> <p>

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.
Publish