请各位前辈帮帮我啊,谢谢了!!!!

betagain 2004-12-22 03:47:43
有sql

select vals from table where id=1

vals是数值,我想让取出来的vals能成为保留2位小数的格式就是 123.45格式,如果小数位数不够补零 例如 123.00 or 123.30 这样的,请问这个sql select vals from table where id=1
应该怎么改写?

谢谢了!!!
...全文
118 12 打赏 收藏 转发到动态 举报
写回复
用AI写文章
12 条回复
切换为时间正序
请发表友善的回复…
发表回复
了缘 2004-12-22
  • 打赏
  • 举报
回复
select cast('123' as numeric(5,2))
结果1列
-----------
123.00

你有没有测试啊,不要没有测试就下结论
betagain 2004-12-22
  • 打赏
  • 举报
回复
算了
既然sql不能解决,还是在应用程序代码里解决吧
chriswu 2004-12-22
  • 打赏
  • 举报
回复
http://community.csdn.net/Expert/topic/3667/3667008.xml?temp=.1682703

问题还没解决,帮帮忙咧~!!
chriswu 2004-12-22
  • 打赏
  • 举报
回复
有个类型转换的吧
我记不得了,谁记得的?帮帮忙~!!
betagain 2004-12-22
  • 打赏
  • 举报
回复
不行,如果是vals是123,那么结果还是123,不能成为123.00

前辈您再帮我看看
haoli_004 2004-12-22
  • 打赏
  • 举报
回复
select cast(vals as numeric(18,2)) as vals from talbe where id=1
betagain 2004-12-22
  • 打赏
  • 举报
回复
不行,如果是vals是123,那么结果还是123,不能成为123.00

前辈您再帮我看看
TTLOVEYOU3344 2004-12-22
  • 打赏
  • 举报
回复
select convert(decimal(10,2),vals) from table where id=1樓主沒搞錯吧,這個語句是對的
TTLOVEYOU3344 2004-12-22
  • 打赏
  • 举报
回复
來晚了,支持樓上
betagain 2004-12-22
  • 打赏
  • 举报
回复
不行,如果是vals是123,那么结果还是123,不能成为123.00

前辈您再帮我看看
了缘 2004-12-22
  • 打赏
  • 举报
回复
select cast(vals as numeric(18,2) as vals from talbe where id=1
skyboy0720 2004-12-22
  • 打赏
  • 举报
回复
select convert(decimal(10,2),vals) as vals from table where id=1

34,575

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server相关内容讨论专区
社区管理员
  • 基础类社区
  • 二月十六
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧