以下选择要求:
CASE WHEN psg_postingtransactions.[AMOUNT] != 0 THEN CAST(REPLACE(REPLACE(REPLICATE('0',12-LEN(RTRIM(psg_postingtransactions [AMOUNT])))+RTRIM(psg_postingtransactions.[AMOUNT]),'.',''), '-', '0') AS NUMERIC) ELSE '00000000000' END
答案 0 :(得分:0)
在MySQL中试试这个:
LPAD(FLOOR(ABS(AMOUNT)*100),11,'0')
但是你的SQL看起来像是TSQL(MS SQL Server)而不是MySQL看到这个SQL Fiddle
假设你确实想要TSQL,那么试试这个:
RIGHT(CONCAT('00000000000',CAST(ABS([AMOUNT])*100 AS INT)),11) AS LEADZERO
或者,您可以使用floor()而不是cast()
RIGHT(CONCAT('00000000000',floor(ABS([AMOUNT])*100)),11) AS LEADZERO
CREATE TABLE psg_postingtransactions
([AMOUNT] decimal(11,2))
;
INSERT INTO psg_postingtransactions
([AMOUNT])
VALUES
(0),
(123.45),
(45678.1),
(-12.56)
;
查询1 :
SELECT
RIGHT(CONCAT('00000000000',cast(ABS([AMOUNT])*100 AS INT)),7) AS LEADZERO
FROM psg_postingtransactions
<强> Results 强>:
| LEADZERO |
|--------------|
| 00000000000 |
| 00000012345 |
| 00004567810 |
| 00000001256 |