• A good QOD today for a couple reasons. The first, of course, is that it brings to our attention the rather cryptic behavior of SQL not being able to convert an empty string to DECIMAL even though it will happily do so to other numeric types (yeah, "numeric types", but not "type numeric". Golly, I love this sort of crazy terminology....).

    The second reason hasn't been mentioned (that I see). I was looking for an option of "All the selects will fail". Why? The code looks as though the author wants to return either an non-null numeric or an empty string, but instead gets a zero. I'm not arguing against SQL's data-typing enforcement as demonstrated here. Rather, I'd emphasize that "proper" coding would obviate the implicit conversion altogether by using a zero as the second operand.

    declare @money money

    ,@bit bit

    ,@decimal decimal

    select isnull(@decimal, 0.0)

    select isnull(@money, 0.0)

    select isnull(@bit, 0)

    And if the empty string were the real objective, an explicit conversion would be needed.

    declare @money money

    ,@bit bit

    ,@decimal decimal

    select isnull(convert(char(20),@decimal), '')

    select isnull(convert(char(20),@money), '')

    select isnull(convert(char(20),@bit), '')