一
create function UpperRMB(@num numeric(14,2))
- returns @rmb table(
- 亿 varchar(2)
- ,仟万 varchar(2)
- ,佰万 varchar(2)
- ,拾万 varchar(2)
- ,万 varchar(2)
- ,仟 varchar(2)
- ,佰 varchar(2)
- ,拾 varchar(2)
- ,元 varchar(2)
- ,角 varchar(2)
- ,分 varchar(2))
- as
- begin
- insert into @rmb
- select
- (case 亿1
- 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 '玖'
- else '' end) as 亿,
- (case 仟万1
- 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 '玖'
- else '' end) as 仟万,
- (case 佰万1
- 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 '玖'
- else '' end) as 佰万,
- (case 拾万1
- 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 '玖'
- else '' end) as 拾万,
- (case 万1
- 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 '玖'
- else '' end) as 万,
- (case 仟1
- 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 '玖'
- else '' end) as 仟,
- (case 佰1
- 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 '玖'
- else '' end) as 佰,
- (case 拾1
- 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 '玖'
- else '' end) as 拾,
- (case 元1
- 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 '玖'
- else '' end) as 元,
- (case 角1
- 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 '玖'
- else '' end) as 角,
- (case 分1
- 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 '玖'
- else '' end) as 分
- from (
- select
- case when len(ltrim(str(@num*100,14)))>=11
- then convert(varchar(10),left(right(ltrim(str(@num*100,14)),11),1) ) else null end as 亿1,
- case when len(ltrim(str(@num*100,14)))>=10
- then convert(varchar(10),left(right(ltrim(str(@num*100,14)),10),1) ) else null end as 仟万1,
- case when len(ltrim(str(@num*100,14)))>=9
- then convert(varchar(10),left(right(ltrim(str(@num*100,14)),9),1) ) else null end as 佰万1,
- case when len(ltrim(str(@num*100,14)))>=8
- then convert(varchar(10),left(right(ltrim(str(@num*100,14)),8),1) ) else null end as 拾万1,
- case when len(ltrim(str(@num*100,14)))>=7
- then convert(varchar(10),left(right(ltrim(str(@num*100,14)),7),1) ) else null end as 万1,
- case when len(ltrim(str(@num*100,14)))>=6
- then convert(varchar(10),left(right(ltrim(str(@num*100,14)),6),1) ) else null end as 仟1,
- case when len(ltrim(str(@num*100,14)))>=5
- then convert(varchar(10),left(right(ltrim(str(@num*100,14)),5),1) ) else null end as 佰1,
- case when len(ltrim(str(@num*100,14)))>=4
- then convert(varchar(10),left(right(ltrim(str(@num*100,14)),4),1) ) else null end as 拾1,
- case when len(ltrim(str(@num*100,14)))>=3
- then convert(varchar(10),left(right(ltrim(str(@num*100,14)),3),1) ) else null end as 元1,
- case when len(ltrim(str(@num*100,14)))>=2
- then convert(varchar(10),left(right(ltrim(str(@num*100,14)),2),1) ) else null end as 角1,
- case when len(ltrim(str(@num*100,14)))>=1
- then convert(varchar(10),left(right(ltrim(str(@num*100,14)),1),1) ) else null end as 分1
- ) kk
- return
- end
- /*
- select * from upperrmb(123456789.12)
- select 亿+'亿'+仟万+'仟'+佰万+'佰'+拾万+'拾'+万+'万'+仟+'仟'+佰+'佰'+拾+'拾'+元+'元'+角+'角'+分+'分' AS [人民币大写]
- from upperrmb(123456789.12)
- --其实单位也可以在函数内设定
- */
- 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)--取最后一位数
- 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
- -- SELECT DBO.TOUPPERCASERMB(123456.789)