/**//*
将数字转换成大写金额的函数
*/

CREATE FUNCTION GetChineseNum (@inputId money)   
RETURNS Nvarchar(4000AS  
BEGIN 
declare @rV Nvarchar(4000)

declare @tmpstr Nvarchar(4000),@M Nvarchar(4000),@K Nvarchar(4000),@I numeric(38,2),
@J int,@lastJ int,@LastV Nvarchar(10),@LastF Nvarchar(10),@LastE Nvarchar(10),@LastVE Nvarchar(10)
set @I=@inputId
select @tmpstr=N\’零壹贰叁肆伍陆柒捌玖分角元拾佰仟万拾佰仟亿拾佰仟\’,@K=N\’\’,@M=cast(cast(@I*100 as bigint

as varchar(800)),@J=len(@M),@LastVE=N\’\’

while @J>=1
begin
set @LastF=substring(@tmpstrcast(substring(@m,len(@M)@j+1,1as bigint)+1,1)
set @LastE=substring(@tmpstr,10+@J,1)
if @LastF<>N\’\’
begin
if @LastV=N\’\’
if (@lastJ>=7 and @j<=7or (@lastJ>=11 and @j<=11 ) or (@lastJ>=3 and @j<=2)
if @J<=2 and @lastJ<=3
set @K=@K+@LastVE+@LastF+@LastE
else
set @K=@K+@LastVE+@LastV+@LastF+@LastE
else
set @K=@K+@LastV+@LastF+@LastE
else
set @K=@K+@LastF+@LastE
select @lastJ=@j,@LastVE=N\’\’
end
else
begin
if @LastVE=N\’\’ and @lastJ>11 set @LastVE=N\’亿\’
if @LastVE=N\’\’ and @lastJ>7 and @lastJ<10 set @LastVE=N\’\’
if @LastVE=N\’\’ and @lastJ>3 and @lastJ<6 set @LastVE=N\’\’
if @LastV<>N\’\’ set @lastJ=@j
end
set @LastV=@LastF
set @J=@J1
end
if @lastJ>=3 set @K=@K+N\’\’
if @lastJ>=2 set @K=@K+N\’\’

set @rv=@K

return @rv
END

版权声明:本文为wf5360308原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://www.cnblogs.com/wf5360308/articles/441305.html