Convert varchar to decimal in sql server 2008

I have this data as varchar '00072330'. How to convert it to decimal code that looks like "723.30" in SQL Server 2008?

+3
source share
2 answers

Try the following:

declare @data as varchar(8)
set @data = '00072330'
print cast(@data as decimal) / 100
+9
source

It:

SELECT CAST('00072330' AS INT)/100.0

... give you:

723.300000

The value .0 is important, otherwise SQL Server will do the math with an integer.

+3
source

Source: https://habr.com/ru/post/1720478/


All Articles