我做錯了什麼?有沒有更好的方法做到這一點,打破長度和字符串並將其轉換爲數值?我越來越varchar數值錯誤?
UPDATE VF_CasINV_Cost
SET TotWgt = CASE
WHEN (Dimension like '%x%') THEN
(cast(left(Dimension, charindex('X', Dimension, 1) - 1) as numeric)) *
(cast(substring(Dimension, 1 + charindex('X', Dimension, 1), len(Dimension)) as numeric))/144.00
WHEN TotWgt = 0 and [Wt/Ft] > 0 THEN (Dimension * [Wt/Ft]) * [Count]
WHEN TotWgt = 0 and [Wt/Sht] > 0 THEN ((Dimension * [Wt/Sht])/100) * [Count]
WHEN TotWgt = 0 and [Wt/Pc] > 0 THEN ((Dimension * [Wt/Pc])/100) * [Count]
ELSE TotWgt
END --TotWgt, Item#, TotWgt, [Wt/Ft], [Wt/Sht], [Wt/Pc], [Count], Dimension, TotWgt
FROM VF_CasINV_Cost
WHERE (CalendarYear = 2010) AND (Item# = Item#) AND (ID = ID) AND (Item# < 99999990)
AND K = 'K' AND D = '' AND C = '' AND (Unit = 'cwt' OR Unit = 'cwts')
你有GOT來簡化它。我們不知道你的模式是什麼樣的,正在處理什麼文本字符串等等。 – n8wrl
你應該提供一個表格模式,以便明確哪一種類型的列是 – sll