mssql2005 ,函数 阿拉伯数字 转成 中文

1个回答

  • 我已经测试过了 整数有效

    alter function fn_numberconvertchinase(@number int)

    returns varchar(20)

    as

    begin

    declare @res varchar(20)

    declare @str varchar(10)

    declare @char char(1)

    set @res = ''

    set @str = cast(@number as varchar)

    set @char = substring(@str,1,1)

    select @res = (case (cast(@char as int))

    when 1 then '一'

    when 2 then '二'

    when 3 then '三'

    when 4 then '四'

    when 5 then '五'

    when 6 then '六'

    when 7 then '七'

    when 8 then '八'

    when 9 then '九'

    else '零' end

    )

    if(len(@str) > 1)

    begin

    select @res = @res + (case len(@str)

    when 2 then '十'

    when 3 then '百'

    when 4 then '千'

    when 5 then '万'

    when 6 then '十'

    when 7 then '百'

    else '' end)

    set @res = @res + dbo.fn_numberconvertchinase(cast(substring(@str,2,len(@str)-1) as int))

    end

    return @res

    end

    select dbo.fn_numberconvertchinase(123)

    ------------

    一百二十三