SET @newNum = IF(
RIGHT("-600.00",1) REGEXP '^[-]' = '-',
REPLACE("-600.00",",",""),
-1*REPLACE(REPLACE("-600.00",",",""),"-","")
);
我不断得到一个截断不正确的DOUBLE值:' - '执行此行时,任何人都知道导致这种情况的原因是什么?
答案 0 :(得分:0)
REGEXP
返回1或0,具体取决于是否匹配。将结果与-
进行比较是不正确的,您可以改为:
DECLARE @oldNum VARCHAR(10);
DECLARE @newNum VARCHAR(10);
SET @oldNum = '600.00-';
SET @newNum = IF(
RIGHT(@oldNum, 1) = '-',
CONCAT('-', REPLACE(REPLACE(@oldNum, ',', ''), '-', '')),
REPLACE(@oldNum, ',', '')
);
SELECT @oldNum, @newNum