0

In SQL Server, the CONVERT function successfully converts an empty string to integer (0):

SELECT CONVERT(int,'') AS Int

However, the CONVERT function fails when converting an empty string to a decimal:

SELECT CONVERT(decimal(3,0),'') AS Decimal

Is there a logical reason for this difference in treatment?

Dale K
  • 21,987
  • 13
  • 41
  • 69
TK Bruin
  • 423
  • 4
  • 14
  • Related https://stackoverflow.com/a/37478728/1260204 – Igor Feb 26 '20 at 18:22
  • 2
    No, there isn't. And one can easily argue that an empty string should throw the same error. This is how a bug becomes a feature. – SMor Feb 26 '20 at 20:09
  • that's the documented behaviour of an empty decimal: https://docs.microsoft.com/en-us/sql/t-sql/functions/cast-and-convert-transact-sql?view=sql-server-ver15#truncating-and-rounding-results. – 1010 Feb 26 '20 at 20:22
  • 1
    @1010, in defense of the OP, "documented" <> "explained", and in this case that's true in spades. – Eric Brandt Feb 26 '20 at 20:51

0 Answers0