Please rate this item: 1 Star2 Stars3 Stars4 Stars5 Stars (No Ratings Yet)
Loading...

SQL: Problem with ISNULL

While going through “Question of the day” from http://www.sqlservercentral.com/, I discovered an issue with the ISNULL function.

If you were to run the query below 1, you will be surprised to hear, that the result returned is “A”.  I am sure you would expect the result to be “ABC”.

The reason for this, is that both parameters of the ISNULL function should be the same data type.  If not, then the data type of the left parameter is used, even if the result is obtained from the right-hand parameter.

To quote the MSDN article (http://msdn.microsoft.com/en-us/library/ms184325.aspx):

ISNULL ( check_expression , replacement_value )


The value of check_expression is returned if it is not NULL; otherwise, replacement_value is returned after it is implicitly converted to the type of check_expression, if the types are different.

  1. Please ensure you test any script taken from my website on a test/development machine, before running on a production server.

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.

CJayMead's SQL Server, Endeca, MS Office Help © 2018