• 金额大写转换


    USE [toy]
    GO
    /****** Object:  StoredProcedure [dbo].[L2U]    Script Date: 03/19/2014 13:15:27 ******/
    SET ANSI_NULLS ON
    GO
    SET QUOTED_IDENTIFIER ON
    GO
    ALTER PROCEDURE [dbo].[L2U] 
    (
    @n_LowerMoney numeric(15,2),
    @v_TransType int,
    @RET VARCHAR(200) output
    )
    AS 
    
    Declare @v_LowerStr VARCHAR(200) -- 小写金额 
    Declare @v_UpperPart VARCHAR(200) 
    Declare @v_UpperStr VARCHAR(200) -- 大写金额
    Declare @i_I int
    
    set nocount On
    
    select @v_LowerStr = LTRIM(RTRIM(STR(@n_LowerMoney,20,2))) --四舍五入为指定的精度并删除数据左右空格
    
    select @i_I = 1
    select @v_UpperStr = ''''
    
    while ( @i_I <= len(@v_LowerStr))
    begin
    select @v_UpperPart = case substring(@v_LowerStr,len(@v_LowerStr) - @i_I + 1,1)
    WHEN '.' THEN ''
    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 ''
    END
    + 
    case @i_I
    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 ''
    WHEN 10 THEN ''
    WHEN 11 THEN ''
    WHEN 12 THEN '亿'
    WHEN 13 THEN ''
    WHEN 14 THEN ''
    WHEN 15 THEN ''
    WHEN 16 THEN ''
    ELSE''''
    END
    select @v_UpperStr = @v_UpperPart + @v_UpperStr
    select @i_I = @i_I + 1
    end
    
    --------print '//v_UpperStr ='+@v_UpperStr +'//'
    
    if ( @v_TransType=0 )
    begin
    select @v_UpperStr = REPLACE(@v_UpperStr,'零拾','') 
    select @v_UpperStr = REPLACE(@v_UpperStr,'零佰','') 
    select @v_UpperStr = REPLACE(@v_UpperStr,'零仟','') 
    select @v_UpperStr = REPLACE(@v_UpperStr,'零零零','')
    select @v_UpperStr = REPLACE(@v_UpperStr,'零零','')
    select @v_UpperStr = REPLACE(@v_UpperStr,'零角零分','')
    select @v_UpperStr = REPLACE(@v_UpperStr,'零分','')
    select @v_UpperStr = REPLACE(@v_UpperStr,'零角','')
    select @v_UpperStr = REPLACE(@v_UpperStr,'零亿零万零元','亿元')
    select @v_UpperStr = REPLACE(@v_UpperStr,'亿零万零元','亿元')
    select @v_UpperStr = REPLACE(@v_UpperStr,'零亿零万','亿')
    select @v_UpperStr = REPLACE(@v_UpperStr,'零万零元','万元')
    select @v_UpperStr = REPLACE(@v_UpperStr,'万零元','万元')
    select @v_UpperStr = REPLACE(@v_UpperStr,'零亿','亿')
    select @v_UpperStr = REPLACE(@v_UpperStr,'零万','')
    select @v_UpperStr = REPLACE(@v_UpperStr,'零元','')
    select @v_UpperStr = REPLACE(@v_UpperStr,'零零','')
    end
    
    -- 对壹元以下的金额的处理 
    if ( substring(@v_UpperStr,1,1)='' )
    begin
    select @v_UpperStr = substring(@v_UpperStr,2,(len(@v_UpperStr) - 1))
    end
    
    if (substring(@v_UpperStr,1,1)= '')
    begin
    select @v_UpperStr = substring(@v_UpperStr,2,(len(@v_UpperStr) - 1))
    end
    
    if (substring(@v_UpperStr,1,1)='')
    begin
    select @v_UpperStr = substring(@v_UpperStr,2,(len(@v_UpperStr) - 1))
    end
    
    if ( substring(@v_UpperStr,1,1)='')
    begin
    select @v_UpperStr = substring(@v_UpperStr,2,(len(@v_UpperStr) - 1))
    end
    
    if (substring(@v_UpperStr,1,1)='')
    begin
    select @v_UpperStr = '零元整'
    end
    
    select @ret=@v_UpperStr
  • 相关阅读:
    线程笔记
    值类型与引用类型
    abstract抽象 抽象方法 不能有实现{} 0907
    接口
    结构
    XML初探
    javaScript中为什么会有变量提升?
    Windows 7实现自动登录(本地账户和域账户)
    WCF 提示 "由于正在读取的 XML 数据的嵌套级比配额所允许的多,因此已超出最大读取深度 (32)" 的解决办法
    也来安个家!
  • 原文地址:https://www.cnblogs.com/armanda/p/3611135.html
Copyright © 2020-2023  润新知