SQL Server將阿拉伯數(shù)字轉(zhuǎn)換成大寫貨幣格式
發(fā)布日期:2021/12/16 6:36:09 瀏覽量:
--該方法用來將阿拉伯數(shù)字的貨幣形式轉(zhuǎn)換成大寫的貨幣形式
--測試:select dbo.toUppercaseRMB(12131415.21);結(jié)果:壹仟貳佰壹拾叁萬壹仟肆佰壹拾伍元貳角壹分整
CREATE function [dbo].[toUppercaseRMB] ( @LowerMoney decimal(18,4))
returns varchar(200)
as
begin
declare @lowerStr varchar(200)
declare @UpperStr varchar(200)
declare @UpperPart varchar(200) --長度
declare @i int
set @lowerStr=ltrim(rtrim(convert(decimal(18,2),round(@LowerMoney,2))))
set @i=1
set @UpperStr=’’
while(@i<=len(@lowerStr))
begin
select @UpperPart=
case substring(@lowerStr,len(@lowerStr)-@i+1,1)--取最后一位數(shù)
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 ’佰’
when 15 then ’仟’
when 16 then ’萬’
else ’’
end
set @UpperStr=@UpperPart+@UpperStr
set @i=@i+1
end
set @UpperStr = REPLACE(@UpperStr,’零拾’,’零’)
set @UpperStr = REPLACE(@UpperStr,’零佰’,’零’)
set @UpperStr = REPLACE(@UpperStr,’零仟零佰零拾’,’零’)
set @UpperStr = REPLACE(@UpperStr,’零仟’,’零’)
set @UpperStr = REPLACE(@UpperStr,’零零零’,’零’)
set @UpperStr = REPLACE(@UpperStr,’零零’,’零’)
set @UpperStr = REPLACE(@UpperStr,’零角零分’,’’)
set @UpperStr = REPLACE(@UpperStr,’零分’,’’)
set @UpperStr = REPLACE(@UpperStr,’零角’,’零’)
set @UpperStr = REPLACE(@UpperStr,’零億零萬零元’,’億元’)
set @UpperStr = REPLACE(@UpperStr,’億零萬零元’,’億元’)
set @UpperStr = REPLACE(@UpperStr,’零億零萬’,’億’)
set @UpperStr = REPLACE(@UpperStr,’零萬零元’,’萬元’)
set @UpperStr = REPLACE(@UpperStr,’萬零元’,’萬元’)
set @UpperStr = REPLACE(@UpperStr,’零億’,’億’)
set @UpperStr = REPLACE(@UpperStr,’零萬’,’萬’)
set @UpperStr = REPLACE(@UpperStr,’零元’,’元’)
set @UpperStr = REPLACE(@UpperStr,’零零’,’零’)
if left(@UpperStr,1)=’元’
set @UpperStr = REPLACE(@UpperStr,’元’,’零元’)
return @UpperStr+’整’
end
馬上咨詢: 如果您有業(yè)務(wù)方面的問題或者需求,歡迎您咨詢!我們帶來的不僅僅是技術(shù),還有行業(yè)經(jīng)驗積累。
QQ: 39764417/308460098 Phone: 13 9800 1 9844 / 135 6887 9550 聯(lián)系人:石先生/雷先生