Forum Discussion

flopir's avatar
flopir
Copper Contributor
Sep 15, 2020

TRY_CONVERT returns wrong result

Hi

 

I was relying on correct result of Try_Convert ( select try_convert(smallint,'+')), but instead of null, I've received 0 as a result. It is the same also with -

 

According to the documentation ( https://docs.microsoft.com/de-de/sql/t-sql/functions/try-convert-transact-sql?view=sql-server-ver15) this should be not possible. Bug or am I missing something ?

I've tried it on SQL 2012 (latest SP4) and SQL 2019 (latest CU)

 

Thanks,

Bobi

1 Reply

  • olafhelper's avatar
    olafhelper
    Bronze Contributor

    The result 0 is correct.

    The plus and minus counts as numeric signs, an addition number is not mandatory here

    Convert returns the same result

     

    select convert(smallint, '+'), convert(smallint, '-')

Resources