0
SET @newNum = IF(
    RIGHT("-600.00",1) REGEXP '^[-]' = '-',
    REPLACE("-600.00",",",""),
    -1*REPLACE(REPLACE("-600.00",",",""),"-","")
);

I keep getting a truncated incorrect DOUBLE value: '-' when executing this line, anyone know what is causing this ?

4

1 回答 1

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
于 2015-03-12T13:04:54.767 回答