您好我是SQL的新手,需要将以下演员语句从varchar(255)
转换为decimal(6,2)
我尝试了很多选项但无法实现
case when [ A 2 cost] = ' £- ' then '0' else [ A 2 cost] end as Costing
目标中[A 2 Cost]
的结果为decimal(6,2)
数据类型,但在源代码中为varchar(255)
答案 0 :(得分:1)
试试这个
case when [ A 2 cost] = ' £- '
then 0.0 else cast([ A 2 cost] as decimal(5,2)) end as Costing
如果其他列在开头包含£,则需要清除它:
case when [ A 2 cost] = ' £- '
then 0.0 else cast(REPLACE([ A 2 cost],'£','') as decimal(5,2)) end as Costing