Was writing some SQL statement, and was testing a nullable VARCHAR column to make sure it was not equal to null and was not an empty string. So I started to write this out as:
WHERE ColumnName IS NOT NULL AND ColumnName <> ''
Well, then I looked at some other code I wrote utilizing the ISNULL function, and realized I could write my SQL as:
WHERE ISNULL( ColumnName, '' ) <> ''
This took care of both options, because if it's null, it returns an empty string, the filters it out with the <> ''
Noted for future use!
No comments:
Post a Comment