添加文本到该行
我是新手,所以请原谅我的简单性。我正在尝试获取总金额,修剪多余的小数位而不是附加一些文本..这一切都有效,直到我尝试 ROUND it
ROUND(CAST(ServiceFee * COUNT(UserID) AS VARCHAR(20)),0) + CAST( '日元' as VARCHAR(20))
提前致谢
I'm a novice so please excuse the simplicity of this. I am trying to get a total ammount, trim the excess decimal places than append some text.. it all works until I try ROUND it
ROUND(CAST(ServiceFee * COUNT(UserID) AS VARCHAR(20)),0) + CAST(' yen' as VARCHAR(20))
Thanks in advance
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在转换之前必须对值进行四舍五入:
You have to round the value before you cast it:
取决于 SQL 的方言。
例如,在 MySQL 中,
+
运算符仅用于数学加法。如果您想要连接这些值,应使用CONCAT()
(在 MySQL 中)或||
运算符(其他支持标准 SQL 的 DBMS) )。您还在 ROUND() 中执行冗余 CAST,因为 ROUND 函数期望其参数为数字。
所以这是 MySQL 中的固定语句:
或者在标准 SQL 中:
(CAST 可能是多余的,但我保留它以防万一你有目的)
Depends on the dialect of SQL.
For example, in MySQL the
+
operator is for mathematical addition only. If you want to concatenate the values, should useCONCAT()
(in MySQL) or the||
operator (other DBMSes that support standard SQL).You're also doing a redundant CAST within ROUND() because the ROUND function expects its argument to be numeric.
So here's the fixed statement in MySQL:
Or in standard SQL:
(the CAST is probably redundant, but I kept it just in case you had a purpose for it)