开发者

Converting varchar to decimal in sql server 2008

开发者 https://www.devze.com 2022-12-08 17:39 出处:网络
I have this data as varchar \'00072330\'. How do I convert it 开发者_如何学Pythonto a decimal that looks like \'723.30\' in SQL Server 2008?Try this:

I have this data as varchar '00072330'. How do I convert it 开发者_如何学Pythonto a decimal that looks like '723.30' in SQL Server 2008?


Try this:

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


This:

SELECT CAST('00072330' AS INT)/100.0

...will give you:

723.300000

The .0 is important, otherwise SQL Server will perform integer math.

0

精彩评论

暂无评论...
验证码 换一张
取 消