SQL CAST 或转换函数
SQL CAST or Convert Function
嗨,我是 SQL 的新手,需要将以下 cast 语句从 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)
试试这个
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
嗨,我是 SQL 的新手,需要将以下 cast 语句从 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)
试试这个
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