前後の不要な 0 をトリムします。
UPDATE yourTable
SET Prix = CASE
WHEN Prix LIKE '%.%[1-9]%' THEN -- has a non-0 after the decimal point
REPLACE(RTRIM(LTRIM(REPLACE(Prix, '0', ' '))), ' ', '0')
WHEN Prix LIKE '%.%' THEN -- only 0's after the decimal point, remove point
REPLACE(REPLACE(RTRIM(LTRIM(REPLACE(Prix, '0', ' '))), ' ', '0'), '.', '')
ELSE -- has no decimal point, only trim leading 0's
REPLACE(LTRIM(REPLACE(Prix, '0', ' ')), ' ', '0')
END
末尾のみをトリミングする場合:
UPDATE yourTable
SET Prix = CASE
WHEN Prix LIKE '%.%[1-9]%' THEN -- has a non-0 after the decimal point
REPLACE(RTRIM(LTRIM(REPLACE(Prix, '0', ' '))), ' ', '0')
ELSE -- only 0's after the decimal point, remove point
REPLACE(REPLACE(RTRIM(LTRIM(REPLACE(Prix, '0', ' '))), ' ', '0'), '.', '')
END
WHERE Prix LIKE '%.%' -- make sure it's decimal
上記はすべて0
の s をスペースに置き換え、組み込みのトリム関数を使用してスペースをトリミングしてから、スペースを0
再び s に置き換えます。