金额格式转换,急用

leonnet 2010-01-07 02:09:48
20000.00
154248.25

要求输出格式为17位不带小数点
00000000002000000
00000000015424825

有人推荐
select right('0000000000'+ltrim(金额*100),17) from tb
但无法实现

请指点哈,急用
...全文
115 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
fly0012008 2010-01-07
  • 打赏
  • 举报
回复
学习
dawugui 2010-01-07
  • 打赏
  • 举报
回复
create table tb(id decimal(18,2))
insert into tb values(20000.00)
insert into tb values(154248.25)
go

select right('0000000000000000' + cast(cast(id*100 as int) as varchar),17) from tb
/*
----------------------------------
00000000002000000
00000000015424825

(所影响的行数为 2 行)
*/

select right('0000000000000000' + ltrim(cast(id*100 as int)),17) from tb
/*
----------------------------------
00000000002000000
00000000015424825

(所影响的行数为 2 行)
*/

drop table tb
SQL77 2010-01-07
  • 打赏
  • 举报
回复
select right('00000000000000000000000000'+ltrim(金额*100),17) from tb 
htl258_Tony 2010-01-07
  • 打赏
  • 举报
回复
select right(REPLICATE('0',17)+ltrim(金额*100),17) from tb --17是总位数.
htl258_Tony 2010-01-07
  • 打赏
  • 举报
回复
[Quote=引用楼主 leonnet 的回复:]
20000.00
154248.25

要求输出格式为17位不带小数点
00000000002000000
00000000015424825

有人推荐
select right('0000000000'+ltrim(金额*100),17) from tb
但无法实现

请指点哈,急用
[/Quote]
select right('0000000000'+ltrim(金额*100),17) from tb --17是总位数.
zb63668331 2010-01-07
  • 打赏
  • 举报
回复

--可以啊
declare @a numeric,@b numeric

set @a = 20000.00
set @b = 154248.25

print right('0000000000'+ltrim(@a*100),17)
print right('0000000000'+ltrim(@b*100),17)
htl258_Tony 2010-01-07
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 playwarcraft 的回复:]
select right('00000000000000000'+ltrim(金额*100),17) from tb

有什么问题??
[/Quote]
同问
playwarcraft 2010-01-07
  • 打赏
  • 举报
回复
select right('00000000000000000'+ltrim(金额*100),17) from tb

有什么问题??

34,593

社区成员

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

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