我正在向表中插入一条消息,内容如下:
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)
因此,格式设置为负数而不是正数。
答案 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