【IT168技术文档】
set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
go
alter FUNCTION [dbo].[fn_numToChn] (@num numeric(14,2))
RETURNS nvarchar(100)
AS
BEGIN
--版权所有:ahshow
DECLARE @n_data nVARCHAR(20),@c_data nVARCHAR(100),@n_str nVARCHAR(10),@i int
SET @n_data=RIGHT(SPACE(14)+CAST(CAST(ABS(@num*100) AS bigint) AS nvarchar(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( N'零壹贰叁肆伍陆柒捌玖',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( N'仟佰拾亿仟佰拾万仟佰拾圆角分',@i,1)
IF SUBSTRING(@c_data,LEN(@c_data)-1,2)= N'亿万'
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