zoukankan      html  css  js  c++  java
  • 将小写金额转换为英文大写的SQL函数

    CREATE FUNCTION [dbo].[f_num_eng] (@num numeric(15,2))
    RETURNS varchar(400WITH ENCRYPTION
    AS
    BEGIN
    --All rights reserved. pbsql
      DECLARE @i int,@hundreds int,@tenth int,@one int
      
    DECLARE @thousand int,@million int,@billion int
      
    DECLARE @numbers varchar(400),@s varchar(15),@result varchar(400)
      
    SET @numbers='one       two       three     four      five      '
                  
    +'six       seven     eight     nine      ten       '
                  
    +'eleven    twelve    thirteen  fourteen  fifteen   '
                  
    +'sixteen   seventeen eighteen  nineteen  '
                  
    +'twenty    thirty    forty     fifty     '
                  
    +'sixty     seventy   eighty    ninety    '
      
    SET @s=RIGHT('000000000000000'+CAST(@num AS varchar(15)),15)
      
    SET @billion=CAST(SUBSTRING(@s,1,3AS int)--将12位整数分成4段:十亿、百万、千、百十个
      SET @million=CAST(SUBSTRING(@s,4,3AS int)
      
    SET @thousand=CAST(SUBSTRING(@s,7,3AS int)
      
    SET @result=''
      
    SET @i=0
      
    WHILE @i<=3
      
    BEGIN
        
    SET @hundreds=CAST(SUBSTRING(@s,@i*3+1,1AS int)--百位0-9
        SET @tenth=CAST(SUBSTRING(@s,@i*3+2,1AS int)
        
    SET @one=(CASE @tenth WHEN 1 THEN 10 ELSE 0 END)+CAST(SUBSTRING(@s,@i*3+3,1AS int)--个位0-19
        SET @tenth=(CASE WHEN @tenth<=1 THEN 0 ELSE @tenth END)--十位0、2-9
        IF (@i=1 and @billion>0 and (@million>0 or @thousand>0 or @hundreds>0)) or
           (
    @i=2 and (@billion>0 or @million>0and (@thousand>0 or @hundreds>0)) or
           (
    @i=3 and (@billion>0 or @million>0 or @thousand>0and (@hundreds>0))
          
    SET @result=@result+''--百位不是0则每段之间加连接符,
        IF (@i=3 and (@billion>0 or @million>0 or @thousand>0and (@hundreds=0 and (@tenth>0 or @one>0)))
          
    SET @result=@result+' and '--百位是0则加连接符AND
        IF @hundreds>0
          
    SET @result=@result+RTRIM(SUBSTRING(@numbers,@hundreds*10-9,10))+' hundred'
        
    IF @tenth>=2 and @tenth<=9
        
    BEGIN
          
    IF @hundreds>0
            
    SET @result=@result+' and '
          
    SET @result=@result+RTRIM(SUBSTRING(@numbers,@tenth*10+171,10))
        
    END
        
    IF @one>=1 and @one<=19
        
    BEGIN
          
    IF @tenth>0
            
    SET @result=@result+'-'
          
    ELSE
            
    IF @hundreds>0
              
    SET @result=@result+' and '
          
    SET @result=@result+RTRIM(SUBSTRING(@numbers,@one*10-9,10))
        
    END
        
    IF @i=0 and @billion>0
          
    SET @result=@result+' billion'
        
    IF @i=1 and @million>0
          
    SET @result=@result+' million'
        
    IF @i=2 and @thousand>0
          
    SET @result=@result+' thousand'
        
    SET @i=@i+1
      
    END
      
    IF SUBSTRING(@s,14,2)<>'00'
      
    BEGIN
        
    SET @result=@result+' point '
        
    IF SUBSTRING(@s,14,1)='0'
          
    SET @result=@result+'zero'
        
    ELSE
          
    SET @result=@result+RTRIM(SUBSTRING(@numbers,CAST(SUBSTRING(@s,14,1AS int)*10-9,10))
        
    IF SUBSTRING(@s,15,1)<>'0'
          
    SET @result=@result+' '+RTRIM(SUBSTRING(@numbers,CAST(SUBSTRING(@s,15,1AS int)*10-9,10))
      
    END
      
    RETURN(@result)
    END

    申明

    非源创博文中的内容均收集自网上,若有侵权之处,请及时联络,我会在第一时间内删除.再次说声抱歉!!!

    博文欢迎转载,但请给出原文连接。

  • 相关阅读:
    解决:导出excel身份证号码显示为科学计数法
    6个出色的基于JQuery的Tab选项卡实例2010/01/29 16:261. jQuery 选项卡界面 / 选项卡结构菜单教程
    dhl:禁用firefox缓存
    artDialog4.0.5
    dhl:解除ASP.NET上传文件大小限制
    dhl:样式在ie不同浏览器下呈现不出来的原因分析
    dhl:artDialog 3.0.4 跨框架下 穿越的问题
    jQuery 1.7 正式版已经可以下载使用。jQuery是一个JavaScript库,它简化了HTML文档遍历,事件处理,动画和为网络快速发展的Ajax交互。jQuery 1.7 版本加入了新的事件API .on() 和 .off(),提
    无法向会话状态服务器发出会话状态请求。请确保 ASP.NET State Service (ASP.NET 状态服务)已启动,并且客户端端口与服务器端口相同。
    专家视角看IT与架构
  • 原文地址:https://www.cnblogs.com/Athrun/p/792046.html
Copyright © 2011-2022 走看看