Converting an empty string to a number...

  • buktseat

    SSChasing Mays

    Points: 611

    Can anyone help me understand why the following works:

    SELECT CONVERT(float, '')

    but this does not:

    SELECT CONVERT(numeric(19,2),'')

    My need for the answer is more than this exercise, but this was the simplest way to ask the question...

     

    Thanks!

  • TUellner

    SSCrazy

    Points: 2387

    Interesting... At first I thought it might have something to do with FLOAT being an approximate data type but the convert works with all other datatypes except numeric (and decimal). Personally, I don't think I would have assumed that an empty string would convert to 0 but it certainly seems like it should be consistent across all data type dealing with numbers.

    Unfortunately, I think the only person who could definitively answer this question would be someone on the Microsoft SQL Server team but I'll be interested to see if anyone jumps in with an answer.

Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply