2016-07-11 44 views
1

嗨,我是新來的SQL,需要以下投聲明將從varchar(255)decimal(6,2)我試過很多選擇,但不能達到它SQL CAST或轉換功能

case when [ A 2 cost] = ' £- ' then '0' else [ A 2 cost] end as Costing 

[A 2 Cost]在目的地的結果decimal(6,2)數據類型,但在源是varchar(255)

+0

我使用Microsoft SQL Server 2000 - 8.00.2066(英特爾X86) –

+0

你是什麼意思'[A 2成本]的意思' ? –

+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 
+1

TY對不起,我不能清楚地解釋問題,因爲我是這個領域的新手,但你把它正確地分類。 –