TRY_CONVERT returns wrong result

Copper Contributor

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

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, '-')