Interesting to note that:
SELECT isnull (' ', GETDATE())
returns a blank string.
This is one of the reasons I don't like letting sql do implicit conversions for me.
The same. 🙂
And thanks to Jaga for the coffee break entertainment!
There isn't any implicit conversion required there: ISNULL returns a value of the sanme type as its first parameter, but that doesn't result in any conversion unless the first parameter is NULL.
select isnull(cast(NULL as varchar(30)), getdate());
returned 'Feb 16 2016 8:07PM', a string with type varchar(30), a couple of minutes ago (WE Time zone here in Las Canarias).
I checked the type by using
select isnull(cast(NULL as varchar(30)), getdate()) X into silly from tally where I=1 to create a table (silly) and looking at the single column's type.
I agree that implicit conversion is often undesirable; but sometimes it's quite useful. The implicit conversion done (if neeed) by ISNULL is a lot less confusing that the implicit conversion done by COALESCE because it desn't have the complication of choosing amongst a bunch of types using type precedence.
And it's a nice little question, that requires one to know the precedence rule.