zoukankan      html  css  js  c++  java
  • sql server数字小写人民币转换成大写人民币(两种方式)

             

      一

    create function UpperRMB(@num numeric(14,2))  

    1. returns @rmb table(  
    2.      亿  varchar(2)  
    3.     ,仟万 varchar(2)  
    4.     ,佰万 varchar(2)  
    5.     ,拾万 varchar(2)  
    6.     ,万      varchar(2)  
    7.     ,仟      varchar(2)  
    8.     ,佰      varchar(2)  
    9.     ,拾      varchar(2)  
    10.     ,元      varchar(2)  
    11.     ,角      varchar(2)  
    12.     ,分      varchar(2))  
    13. as  
    14. begin  
    15. insert into @rmb  
    16. select   
    17.     (case 亿1            
    18. when 0 then '零'            
    19. when 1 then '壹'            
    20. when 2 then '贰'            
    21. when 3 then '叁'            
    22. when 4 then '肆'            
    23. when 5 then '伍'            
    24. when 6 then '陆'            
    25. when 7 then '柒'            
    26. when 8 then '捌'            
    27. when 9 then '玖'  
    28. else '' end) as 亿,    
    29.     (case 仟万1            
    30. when 0 then '零'            
    31. when 1 then '壹'            
    32. when 2 then '贰'            
    33. when 3 then '叁'            
    34. when 4 then '肆'            
    35. when 5 then '伍'            
    36. when 6 then '陆'            
    37. when 7 then '柒'            
    38. when 8 then '捌'            
    39. when 9 then '玖'  
    40. else '' end) as 仟万,    
    41.     (case 佰万1            
    42. when 0 then '零'            
    43. when 1 then '壹'            
    44. when 2 then '贰'            
    45. when 3 then '叁'            
    46. when 4 then '肆'            
    47. when 5 then '伍'            
    48. when 6 then '陆'            
    49. when 7 then '柒'            
    50. when 8 then '捌'            
    51. when 9 then '玖'   
    52. else '' end) as 佰万,      
    53.     (case 拾万1            
    54. when 0 then '零'            
    55. when 1 then '壹'            
    56. when 2 then '贰'            
    57. when 3 then '叁'            
    58. when 4 then '肆'            
    59. when 5 then '伍'            
    60. when 6 then '陆'            
    61. when 7 then '柒'            
    62. when 8 then '捌'            
    63. when 9 then '玖'   
    64. else '' end) as 拾万,             
    65.     (case 万1            
    66. when 0 then '零'            
    67. when 1 then '壹'            
    68. when 2 then '贰'            
    69. when 3 then '叁'            
    70. when 4 then '肆'            
    71. when 5 then '伍'            
    72. when 6 then '陆'            
    73. when 7 then '柒'            
    74. when 8 then '捌'            
    75. when 9 then '玖'   
    76. else '' end) as 万,            
    77.     (case 仟1            
    78. when 0 then '零'            
    79. when 1 then '壹'            
    80. when 2 then '贰'            
    81. when 3 then '叁'            
    82. when 4 then '肆'            
    83. when 5 then '伍'            
    84. when 6 then '陆'            
    85. when 7 then '柒'            
    86. when 8 then '捌'            
    87. when 9 then '玖'   
    88. else '' end) as 仟,            
    89.     (case 佰1            
    90. when 0 then '零'            
    91. when 1 then '壹'            
    92. when 2 then '贰'            
    93. when 3 then '叁'            
    94. when 4 then '肆'            
    95. when 5 then '伍'            
    96. when 6 then '陆'            
    97. when 7 then '柒'            
    98. when 8 then '捌'            
    99. when 9 then '玖'   
    100. else '' end) as 佰,            
    101.     (case 拾1            
    102. when 0 then '零'            
    103. when 1 then '壹'            
    104. when 2 then '贰'            
    105. when 3 then '叁'            
    106. when 4 then '肆'            
    107. when 5 then '伍'            
    108. when 6 then '陆'            
    109. when 7 then '柒'            
    110. when 8 then '捌'            
    111. when 9 then '玖'   
    112. else '' end) as 拾,            
    113.     (case 元1            
    114. when 0 then '零'            
    115. when 1 then '壹'            
    116. when 2 then '贰'            
    117. when 3 then '叁'            
    118. when 4 then '肆'            
    119. when 5 then '伍'            
    120. when 6 then '陆'            
    121. when 7 then '柒'            
    122. when 8 then '捌'            
    123. when 9 then '玖'   
    124. else '' end) as 元,            
    125.     (case 角1            
    126. when 0 then '零'            
    127. when 1 then '壹'            
    128. when 2 then '贰'            
    129. when 3 then '叁'            
    130. when 4 then '肆'            
    131. when 5 then '伍'            
    132. when 6 then '陆'            
    133. when 7 then '柒'            
    134. when 8 then '捌'            
    135. when 9 then '玖'   
    136. else '' end) as 角,            
    137.     (case 分1            
    138. when 0 then '零'            
    139. when 1 then '壹'            
    140. when 2 then '贰'            
    141. when 3 then '叁'            
    142. when 4 then '肆'            
    143. when 5 then '伍'            
    144. when 6 then '陆'            
    145. when 7 then '柒'            
    146. when 8 then '捌'            
    147. when 9 then '玖'   
    148. else '' end) as 分      
    149. from (       
    150. select   
    151. case when len(ltrim(str(@num*100,14)))>=11   
    152. then convert(varchar(10),left(right(ltrim(str(@num*100,14)),11),1) ) else null end as 亿1,  
    153. case when len(ltrim(str(@num*100,14)))>=10   
    154. then convert(varchar(10),left(right(ltrim(str(@num*100,14)),10),1) ) else null end as 仟万1,  
    155. case when len(ltrim(str(@num*100,14)))>=9   
    156. then convert(varchar(10),left(right(ltrim(str(@num*100,14)),9),1) ) else null end as 佰万1,    
    157. case when len(ltrim(str(@num*100,14)))>=8   
    158. then convert(varchar(10),left(right(ltrim(str(@num*100,14)),8),1) ) else null end as 拾万1,       
    159. case when len(ltrim(str(@num*100,14)))>=7   
    160. then convert(varchar(10),left(right(ltrim(str(@num*100,14)),7),1) ) else null end as 万1,            
    161. case when len(ltrim(str(@num*100,14)))>=6   
    162. then convert(varchar(10),left(right(ltrim(str(@num*100,14)),6),1) ) else null end as 仟1,            
    163. case when len(ltrim(str(@num*100,14)))>=5   
    164. then convert(varchar(10),left(right(ltrim(str(@num*100,14)),5),1) ) else null end as 佰1,            
    165. case when len(ltrim(str(@num*100,14)))>=4   
    166. then convert(varchar(10),left(right(ltrim(str(@num*100,14)),4),1) ) else null end as 拾1,            
    167. case when len(ltrim(str(@num*100,14)))>=3   
    168. then convert(varchar(10),left(right(ltrim(str(@num*100,14)),3),1) ) else null end as 元1,            
    169. case when len(ltrim(str(@num*100,14)))>=2   
    170. then convert(varchar(10),left(right(ltrim(str(@num*100,14)),2),1) ) else null end as 角1,            
    171. case when len(ltrim(str(@num*100,14)))>=1   
    172. then convert(varchar(10),left(right(ltrim(str(@num*100,14)),1),1) ) else null end as 分1      
    173.  ) kk  
    174. return  
    175. end  
    176. /*  
    177. select * from upperrmb(123456789.12)  
    178. select 亿+'亿'+仟万+'仟'+佰万+'佰'+拾万+'拾'+万+'万'+仟+'仟'+佰+'佰'+拾+'拾'+元+'元'+角+'角'+分+'分' AS [人民币大写]   
    179. from upperrmb(123456789.12)  
    180. --其实单位也可以在函数内设定  
    181. */  

     
      1. CREATE function dbo.toUppercaseRMB ( @LowerMoney decimal(18,4))  
      2. returns varchar(200)   
      3. as      
      4. begin      
      5.    declare @lowerStr varchar(200)      
      6.    declare @UpperStr varchar(200)      
      7.    declare @UpperPart varchar(200)     --长度      
      8.    declare @i int       
      9.          
      10.    set @lowerStr=ltrim(rtrim(convert(decimal(18,2),round(@LowerMoney,2))))      
      11.    set @i=1      
      12.    set @UpperStr=''      
      13.          
      14.    while(@i<=len(@lowerStr))      
      15.    begin      
      16.         select @UpperPart=  
      17.         case substring(@lowerStr,len(@lowerStr)-@i+1,1)--取最后一位数  
      18.             when  '.' then '元'      
      19.             when  '0' then '零'      
      20.             when  '1' then '壹'      
      21.             when  '2' then '贰'      
      22.             when  '3' then '叁'      
      23.             when  '4' then '肆'      
      24.             when  '5' then '伍'      
      25.             when  '6' then '陆'      
      26.             when  '7' then '柒'      
      27.             when  '8' then '捌'      
      28.             when  '9' then '玖'      
      29.         end      
      30.         +      
      31.         case @i       
      32.             when 1 then  '分'      
      33.             when 2 then  '角'      
      34.             when 3 then  ''      
      35.             when 4 then  ''      
      36.             when 5 then  '拾'      
      37.             when 6 then  '佰'      
      38.             when 7 then  '仟'      
      39.             when 8 then  '万'      
      40.             when 9 then  '拾'      
      41.             when 10 then '佰'      
      42.             when 11 then '仟'      
      43.             when 12 then '亿'      
      44.             when 13 then '拾'      
      45.             when 14 then '佰'      
      46.             when 15 then '仟'      
      47.             when 16 then '万'      
      48.             else ''      
      49.         end      
      50.         set @UpperStr=@UpperPart+@UpperStr      
      51.         set @i=@i+1      
      52.     end       
      53.     set @UpperStr = REPLACE(@UpperStr,'零拾','零')       
      54.     set @UpperStr = REPLACE(@UpperStr,'零佰','零')       
      55.     set @UpperStr = REPLACE(@UpperStr,'零仟零佰零拾','零')       
      56.     set @UpperStr  = REPLACE(@UpperStr,'零仟','零')      
      57.     set @UpperStr = REPLACE(@UpperStr,'零零零','零')      
      58.     set @UpperStr = REPLACE(@UpperStr,'零零','零')      
      59.     set @UpperStr = REPLACE(@UpperStr,'零角零分','')      
      60.     set @UpperStr = REPLACE(@UpperStr,'零分','')      
      61.     set @UpperStr = REPLACE(@UpperStr,'零角','零')      
      62.     set @UpperStr = REPLACE(@UpperStr,'零亿零万零元','亿元')      
      63.     set @UpperStr = REPLACE(@UpperStr,'亿零万零元','亿元')      
      64.     set @UpperStr = REPLACE(@UpperStr,'零亿零万','亿')      
      65.     set @UpperStr = REPLACE(@UpperStr,'零万零元','万元')      
      66.     set @UpperStr = REPLACE(@UpperStr,'万零元','万元')      
      67.     set @UpperStr = REPLACE(@UpperStr,'零亿','亿')      
      68.     set @UpperStr = REPLACE(@UpperStr,'零万','万')      
      69.     set @UpperStr = REPLACE(@UpperStr,'零元','元')      
      70.     set @UpperStr = REPLACE(@UpperStr,'零零','零')      
      71.     if left(@UpperStr,1)='元'      
      72.         set @UpperStr = REPLACE(@UpperStr,'元','零元')      
      73.   
      74.   return @UpperStr+'整'      
      75. end      
      76.   
      77. --      SELECT DBO.TOUPPERCASERMB(123456.789)  
  • 相关阅读:
    WebService cxf提供接口
    在文件系统的某一个目录中查找某一个字符串
    在notepad++中插件安装的办法
    windows中的oracle12SE后启动的系统服务的列表
    在windows环境初步了解tuxedo
    使用MS VS的命令来编译C++程序
    我所常用的git命令
    使用python对文件中的数值进行累加
    C++中继承关系中的同名隐藏和对策
    用eclipse来制作并使用可执行的jar文件
  • 原文地址:https://www.cnblogs.com/ysjBoke/p/4835218.html
Copyright © 2011-2022 走看看