SQL小写金额换大写金额

/*转换小写数字为大写数字*/

declare @l varchar(100) -- 小写金额
declare @u1 varchar(100)
declare @u varchar(100)-- 大写金额
declare @i int
set @l='123456000.789'
set @i=1
set @l = ltrim(rtrim(str(@l,20,2))) --保留两位小数并删除数据左右空格

select @u = '' --置初值
while ( @i <= len(@l))--大于字符串长度即退出
begin
set @u1=
case substring(@l,len(@l) - @i + 1,1)
--从字符串最后一位倒序取字符
when '.' then '圆'
when '0' then '零'
when '1' then '壹'
when '2' then '贰'
when '3' then '叁'
when '4' then '肆'
when '5' then '伍'
when '6' then '陆'
when '7' then '柒'
when '8' then '捌'
when '9' then '玖'
end
+
case @i

when 1 then '分'
when 2 then '角'
when 3 then ''
when 4 then ''
when 5 then '拾'
when 6 then '佰'
when 7 then '仟'
when 8 then '万'
when 9 then '拾'
when 10 then '佰'
when 11 then '仟'
when 12 then '亿'
when 13 then '拾'
when 14 then '佰'
else ''
end
set @u = @u1+@u
--连接上次循环的字符串,从右向左倒序连接
set @i = @i+1
--递增,下次循环取上一字符
end
select @u = replace(@u,'零圆','零')
select @u = replace(@u,'零拾','零')
select @u = replace(@u,'零佰','零')
select @u = replace(@u,'零仟','零')
select @u = replace(@u,'零零零','零')
select @u = replace(@u,'零零','零')
select @u = replace(@u,'零角零分','整')
select @u = replace(@u,'零分','整')
select @u = replace(@u,'零角','零')
select @u = replace(@u,'零亿零万零元','亿元')
select @u = replace(@u,'亿零万零元','亿元')
select @u = replace(@u,'零亿零万','亿')
select @u = replace(@u,'零万零元','万元')
select @u = replace(@u,'万零元','万元')
select @u = replace(@u,'零亿','亿')
select @u = replace(@u,'零万','万')
select @u = replace(@u,'零元','元')
select @u = replace(@u,'零零','零')

print @u
 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值