表标量值函数数组金额转换为大写金额

USE [jy_dev]
GO
/****** Object:  UserDefinedFunction [dbo].[toUppercaseRMB]    Script Date: 2021/6/28 18:20:06 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER 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)--取最后一位数
			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    
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值