【发布时间】:2021-10-30 02:31:18
【问题描述】:
我有一张包含多个实数的表格。它看起来像这样:
| ParticipantId | GWF_Score |
|---|---|
| 123 | 185 |
| 456 | 193,5 |
| 789 | 80 |
我已经构建了一个存储过程,它以 XML 格式返回这个表。
我必须像表格中写的那样打印分数。
如果我这样写
convert(decimal, GWF_Score) as [@points],
我会得到 185,194,80
如果我这样写
cast(GWF_Score as decimal(10,2)) as [@points],
我会得到 185.00, 193.50, 80.00
如果我这样写
(case when GWF_Score % 1 != 0 then cast(GWF_Score as decimal(10,2)) else convert(decimal, GWF_Score)end) as [@points],
我会收到一条错误消息,指出 real 和 int 与模运算符不兼容。
【问题讨论】:
-
我建议在您的表示层而不是在数据库中执行此操作。数据库用于保存数据。您的表示层用于格式化。
-
这看起来像是您的表示层的工作,不是 RDBMS。
标签: sql tsql casting type-conversion