|
发表于 2020-7-13 09:45:01
|
显示全部楼层
alter function to_up(@num numeric(14,2))
returns varchar(100)
as
begin
declare @ndata varchar(20),@cdata varchar(100)
declare @nstr varchar(10),@zflag bit,@t varchar(10),@i int
set @ndata=RIGHT(SPACE(14)+CAST(CAST(ABS(@num*100) AS bigint) AS varchar(20)),14)
set @cdata=''
set @zflag=0;set @i=1
while @i<=14
begin
set @nstr=substring(@ndata,@i,1)
if @nstr<>' '
begin
--数字
set @nstr=SUBSTRING('零壹贰叁肆伍陆柒捌玖',CAST(@nstr AS int)+1,1)
set @t=SUBSTRING('仟佰拾亿仟佰拾万仟佰拾圆角分',@i,1)
if @nstr='零'
begin
if @t in ('亿','万','圆')
set @cdata=@cdata+@t
if @zflag=0
set @zflag=1
end
else
begin
if @zflag=1
begin
if @t='圆'
set @cdata=@cdata+@t
else
set @cdata=@cdata+'零'+@nstr+@t
set @zflag=0
end
else
set @cdata=@cdata+@nstr+@t
end
end
set @i=@i+1
end
IF @num<0
SET @cdata='(负数)'+@cdata
IF @num=0
SET @cdata='零圆'
IF @nstr='零'
SET @cdata=@cdata+'整'
RETURN(@cdata)
end
|
|