SQL中是否可以格式化小数点格式,以便在括号中显示负小数点

时间:2019-01-30 15:38:02

标签: sql formatting decimal

我正在向表中插入一条消息,内容如下:

The old amount of 10.00 is changed to new amount of -20.00.

是否可以格式化它,因此当插入表中时,它显示为

The old amount of 10.00 is changed to new amount of ($20.00)

因此,格式设置为负数而不是正数。

1 个答案:

答案 0 :(得分:0)

我的问题的答案如下:

'The old amount of ' 
+ CASE WHEN @OldAmount >= 0 THEN CAST(@OldAmount AS VARCHAR) ELSE '($' + CONVERT(VARCHAR,ABS(@OldAmount), 106) + ')' END
+ ' is changed to new amount of ' + CASE WHEN @NewAmount >= 0 THEN CAST(@NewAmount AS VARCHAR) ELSE '($' + CONVERT(VARCHAR, ABS(@NewAmount), 106) + ')' END