Quantcast
Channel: Transact-SQL forum
Viewing all articles
Browse latest Browse all 23857

Failed conversion from varchar to int for negative decimal "-119.00"

$
0
0

So, if you take a look at the following bit of code it produces the following error:
     declare @x varchar(30)=-119.00
     select @x
     select cast(@x as int)

"Conversion failed when converting the varchar value '-119.00' to data type int."

Now this part works fine:
     select cast(-119.00 as int)

As does this:
     declare @x varchar(30)=-119.00
     select @x
     select cast(cast(@x as decimal) as int)

My question is, why does the value have to be converted from a varchar to a number value before it gets converted to an INT?


Viewing all articles
Browse latest Browse all 23857

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>