欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

SQL 数字转为中文大写

程序员文章站 2022-05-22 19:05:30
USE [SPECIAL_BLD]GO SET ANSI_NULLS ONGO SET QUOTED_IDENTIFIER ONGO CREATE FUNCTION [dbo].[get_upper] ( @num numeric(18,5))RETURNS VARCHAR(500)ASBEGIN ......

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