• Danny Ocean (5/10/2013)


    Good question, but Explanation is not completed or require more details.

    I think hugo can help us.

    Unfortunately, I can't. This is not consistent at all. In many other cases, SQL Server will complain when it has to conjure a data type for nulls out of thin air, and it would have made much more sense if it did so for this case as well.

    (For example, compare "SELECT COALESCE(NULL, NULL);" with "SELECT COALESCE(NULL, CAST(NULL AS varchar(10)));")

    I suspect that the reason it defaults to int is purely some internal implementation issue - int is probably first or last in some internal list that happens to be used here.


    Hugo Kornelis, SQL Server/Data Platform MVP (2006-2016)
    Visit my SQL Server blog: https://sqlserverfast.com/blog/
    SQL Server Execution Plan Reference: https://sqlserverfast.com/epr/