SQL 数字转为中文大写
use [special_bld]
go
set ansi_nulls on
go
set quoted_identifier on
go
create function [dbo].[get_upper]
(
@num numeric(18,5)
)
returns varchar(500)
as
begin
declare @n_data varchar(20),@c_data varchar(100),@n_str varchar(10),@i int
set @n_data=right(space(14)+cast(cast(abs(@num*100) as bigint) as varchar(20)),14)
set @c_data=''
set @i=1
while @i<=14
begin
set @n_str=substring(@n_data,@i,1)
if @n_str<>' '
begin
if not ((substring(@n_data,@i,2)='00') or
((@n_str='0') and ((@i=4) or (@i=8) or (@i=12) or (@i=14))))
set @c_data=@c_data+substring('零壹贰叁肆伍陆柒捌玖',cast(@n_str as int)+1,1)
if not ((@n_str='0') and (@i<>4) and (@i<>8) and (@i<>12))
set @c_data=@c_data+substring('仟佰拾亿仟佰拾万仟佰拾圆角分',@i,1)
if substring(@c_data,len(@c_data)-1,2)='亿万'
set @c_data=substring(@c_data,1,len(@c_data)-1)
end
set @i=@i+1
end
if @num<0
set @c_data='(负数)'+@c_data
if @num=0
set @c_data='零圆'
if @n_str='0'
set @c_data=@c_data+'整'
return(@c_data)
end
go
上一篇: 周瑜英年早逝后,小乔最后结局怎么样了?
下一篇: 佟贵妃:13岁就嫁给顺治,14岁生下康熙