The COALESCE function is great for implementing elegant conditional logic in SQL Server queries and procedures.
But it can bite you. I didn’t fully understand the implications of this statement in the documentation until today:
Returns the data type of expression with the highest data type precedence.
SQL Server has many built-in data types. Books Online has a page that ranks them by precedence.
I found a blog post that documents this better than I can do just now. The jist is that COALSCE can fail if its arguments are of incomparable types, and the order of the parameters can determine whether two values are compared.