set ANSI_NULLS ON set QUOTED_IDENTIFIER ON go --============================================= -- Author: <---> -- Create date: <2008-3-4> -- Description: <将阿拉伯数字转换成汉字大写> --============================================= ALTER function [dbo].[ConvertNumberToChinese](@inputId money) RETURNS Nvarchar(4000) AS 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 set @K=N'' if @I<0 begin set @I=0-@I set @K=N'负' end if @I=0return N'零元整' select @tmpstr=N'零壹贰叁肆伍陆柒捌玖分角元拾佰仟万拾佰仟亿拾佰仟',@M=cast(cast(@I*100as bigint) as varchar(800)),@J=len(@M),@LastVE=N'' while @J>=1 begin set @LastF=substring(@tmpstr, cast(substring(@m,len(@M)-@j+1,1) as bigint)+1,1) set @LastE=substring(@tmpstr,10+@J,1) if @LastF<>N'零' begin if @LastV=N'零' if (@lastJ>=7 and @j<7) or (@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>11set @LastVE=N'亿' if @LastVE=N'' and @lastJ>7 and @lastJ<10set @LastVE=N'万' if @LastVE=N'' and @lastJ>3 and @lastJ<6set @LastVE=N'元' if @LastVE=N'' and @lastJ>2set @LastVE=N'零' if @LastV<>N'零'set @lastJ=@j end set @LastV=@LastF set @J=@J-1 end if @lastJ>=6set @K=@K+@LastVE if @lastJ>=3set @K=@K+N'元' if @lastJ>1 or (@lastJ=1 and @LastV=N'零') set @K=@K+N'整' set @rv=@K return @rv END