• sql 数字转人民币大写函数(两种方法)


      create function UpperRMB(@num numeric(14,2))
     returns @rmb table(
         亿    varchar(2)
        ,仟万    varchar(2)
        ,佰万    varchar(2)
        ,拾万    varchar(2)
        ,万        varchar(2)
        ,仟        varchar(2)
        ,佰        varchar(2)
        ,拾        varchar(2)
        ,元        varchar(2)
        ,角        varchar(2)
        ,分        varchar(2))
     as
     begin
     insert into @rmb
     select 
        (case 亿1          
            when 0 then ''          
            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) as 亿,  
        (case 仟万1          
            when 0 then ''          
            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) as 仟万,  
        (case 佰万1          
            when 0 then ''          
            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) as 佰万,    
        (case 拾万1          
            when 0 then ''          
            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) as 拾万,           
        (case 万1          
            when 0 then ''          
            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) as 万,          
        (case 仟1          
            when 0 then ''          
            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) as 仟,          
        (case 佰1          
            when 0 then ''          
            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) as 佰,          
        (case 拾1          
            when 0 then ''          
            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) as 拾,          
        (case 元1          
            when 0 then ''          
            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) as 元,          
        (case 角1          
            when 0 then ''          
            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) as 角,          
        (case 分1          
            when 0 then ''          
            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) asfrom (     
     select 
        case when len(ltrim(str(@num*100,14)))>=11 
            then convert(varchar(10),left(right(ltrim(str(@num*100,14)),11),1) ) else null end as 亿1,
        case when len(ltrim(str(@num*100,14)))>=10 
            then convert(varchar(10),left(right(ltrim(str(@num*100,14)),10),1) ) else null end as 仟万1,
        case when len(ltrim(str(@num*100,14)))>=9 
            then convert(varchar(10),left(right(ltrim(str(@num*100,14)),9),1) ) else null end as 佰万1,  
        case when len(ltrim(str(@num*100,14)))>=8 
            then convert(varchar(10),left(right(ltrim(str(@num*100,14)),8),1) ) else null end as 拾万1,     
        case when len(ltrim(str(@num*100,14)))>=7 
            then convert(varchar(10),left(right(ltrim(str(@num*100,14)),7),1) ) else null end as 万1,          
        case when len(ltrim(str(@num*100,14)))>=6 
            then convert(varchar(10),left(right(ltrim(str(@num*100,14)),6),1) ) else null end as 仟1,          
        case when len(ltrim(str(@num*100,14)))>=5 
            then convert(varchar(10),left(right(ltrim(str(@num*100,14)),5),1) ) else null end as 佰1,          
        case when len(ltrim(str(@num*100,14)))>=4 
            then convert(varchar(10),left(right(ltrim(str(@num*100,14)),4),1) ) else null end as 拾1,          
        case when len(ltrim(str(@num*100,14)))>=3 
            then convert(varchar(10),left(right(ltrim(str(@num*100,14)),3),1) ) else null end as 元1,          
        case when len(ltrim(str(@num*100,14)))>=2 
            then convert(varchar(10),left(right(ltrim(str(@num*100,14)),2),1) ) else null end as 角1,          
        case when len(ltrim(str(@num*100,14)))>=1 
            then convert(varchar(10),left(right(ltrim(str(@num*100,14)),1),1) ) else null end as 分1    
     ) kk
     return
     end
     
    /*
    select * from upperrmb(123456789.12)
    
    select 亿+'亿'+仟万+'仟'+佰万+'佰'+拾万+'拾'+万+'万'+仟+'仟'+佰+'佰'+拾+'拾'+元+'元'+角+'角'+分+'分' AS [人民币大写] 
    from upperrmb(123456789.12)
    
    --其实单位也可以在函数内设定
    */
  • 相关阅读:
    php中的list()用法中要注意的地方
    怎么让小白理解intel处理器(CPU)的分类
    CPU的历史
    【主板上各种接口和附属部件科普】
    NVMe SSD是什么?
    带你认识SATA、mSATA 、PCIe和M.2四种接口
    那些长短不一的PCI-E插槽都有什么不一样?
    ceph 指定OSD创建pool
    ceph cache pool配置
    搭建ceph集群(单节点)
  • 原文地址:https://www.cnblogs.com/accumulater/p/6225657.html
Copyright © 2020-2023  润新知