今天看啥
热点:

用SQL将数字转换为中文数字,sql转换中文数字


 


IF OBJECT_ID('fn_GetChnNum') IS NOT NULL
BEGIN
DROP FUNCTION dbo.fn_GetChnNum;
END;
GO
CREATE FUNCTION fn_GetChnNum ( @Number AS BIGINT )
RETURNS VARCHAR(100)
AS
BEGIN
DECLARE @ChnNum VARCHAR(100);
IF LEN(@Number) = 1
BEGIN
SET @ChnNum = SUBSTRING('零一二三四五六七八九', @Number + 1, 1);
END;
ELSE
BEGIN
DECLARE @Len INTEGER;
DECLARE @strNum AS VARCHAR(100);
DECLARE @i AS INTEGER;
DECLARE @NumWs AS INTEGER;

SET @ChnNum = '';

SET @strNum = CAST(@Number AS VARCHAR(100));
SELECT @Len = LEN(@strNum);
SET @i = 1;

WHILE @i <= @Len
BEGIN
SET @ChnNum = @ChnNum
+ dbo.fn_GetChnNum(SUBSTRING(@strNum, @i, 1));
SET @NumWs = @Len + 1 - @i;
IF @NumWs > 1
BEGIN
SET @ChnNum = @ChnNum
+ CASE WHEN @NumWs % 4 = 0 THEN '千'
WHEN @NumWs % 2 = 0 THEN '十'
WHEN @NumWs % 8 = 1 THEN '亿'
WHEN @NumWs % 4 = 1 THEN '万'
WHEN @NumWs % 2 = 1 THEN '百'
ELSE ''
END;
END;
SET @i = @i + 1;
END;

RETURN @ChnNum;
END;

RETURN @ChnNum;
END;

GO

--测试
SELECT dbo.fn_GetChnNum(1376767661224);

 


 

www.bkjia.comtruehttp://www.bkjia.com/Sql_Server/1283994.htmlTechArticle用SQL将数字转换为中文数字,sql转换中文数字 IF OBJECT_ID('fn_GetChnNum') IS NOT NULL BEGIN DROP FUNCTION dbo.fn_GetChnNum; END; GO CREATE FUNCTION fn_GetChnNum ( @...

相关文章

相关搜索: 阿拉伯数字

帮客评论

视觉看点