zoukankan      html  css  js  c++  java
  • 小写金额转换成大写(sql server)

    if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[L2U]') and xtype in (N'FN', N'IF', N'TF'))
    drop function [dbo].[L2U]
    GO

    CREATE FUNCTION dbo.L2U(@n_LowerMoney numeric(15,2),@v_TransType int)
    RETURNS VARCHAR(200) AS
    BEGIN
    Declare @v_LowerStr VARCHAR(200) -- 小写金额
    Declare @v_UpperPart VARCHAR(200)
    Declare @v_UpperStr VARCHAR(200) -- 大写金额
    Declare @i_I int

    set @v_LowerStr = LTRIM(RTRIM(ROUND(@n_LowerMoney,2))) --四舍五入为指定的精度并删除数据左右空格
    set @i_I = 1
    set @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
    set @v_UpperStr = @v_UpperPart + @v_UpperStr
    set @i_I = @i_I + 1
    end

    if ( 0 = @v_TransType)
    begin
    set @v_UpperStr = REPLACE(@v_UpperStr,'零拾','')
    set @v_UpperStr = REPLACE(@v_UpperStr,'零佰','')
    set @v_UpperStr = REPLACE(@v_UpperStr,'零仟','')
    set @v_UpperStr = REPLACE(@v_UpperStr,'零零零','')
    set @v_UpperStr = REPLACE(@v_UpperStr,'零零','')
    set @v_UpperStr = REPLACE(@v_UpperStr,'零角零分','')
    set @v_UpperStr = REPLACE(@v_UpperStr,'零分','')
    set @v_UpperStr = REPLACE(@v_UpperStr,'零角','')
    set @v_UpperStr = REPLACE(@v_UpperStr,'零亿零万零元','亿元')
    set @v_UpperStr = REPLACE(@v_UpperStr,'亿零万零元','亿元')
    set @v_UpperStr = REPLACE(@v_UpperStr,'零亿零万','亿')
    set @v_UpperStr = REPLACE(@v_UpperStr,'零万零元','万元')
    set @v_UpperStr = REPLACE(@v_UpperStr,'万零元','万元')
    set @v_UpperStr = REPLACE(@v_UpperStr,'零亿','亿')
    set @v_UpperStr = REPLACE(@v_UpperStr,'零万','')
    set @v_UpperStr = REPLACE(@v_UpperStr,'零元','')
    set @v_UpperStr = REPLACE(@v_UpperStr,'零零','')
    end

    -- 对壹元以下的金额的处理
    if ( '' = substring(@v_UpperStr,1,1))
    begin
    set @v_UpperStr = substring(@v_UpperStr,2,(len(@v_UpperStr) - 1))
    end

    if ( '' = substring(@v_UpperStr,1,1))
    begin
    set @v_UpperStr = substring(@v_UpperStr,2,(len(@v_UpperStr) - 1))
    end

    if ( '' = substring(@v_UpperStr,1,1))
    begin
    set @v_UpperStr = substring(@v_UpperStr,2,(len(@v_UpperStr) - 1))
    end

    if ( '' = substring(@v_UpperStr,1,1))
    begin
    set @v_UpperStr = substring(@v_UpperStr,2,(len(@v_UpperStr) - 1))
    end

    if ('' = substring(@v_UpperStr,1,1))
    begin
    set @v_UpperStr = '零元整'
    end
    return @v_UpperStr
    END
    GO

    select dbo.L2U(12.93,1),dbo.L2U(12.93,0)
  • 相关阅读:
    (转)在SQL Server 2016,Visual Studio 2017环境下,连接数据库屡屡失败,在connectionString上出的问题
    WPF中,DataGrid最左边多出一行的解决方案
    (转)SQL注入攻击简介
    Bot Framework:Activity类简明指南
    微软Bot Framework文档中,关于Sign-in Card的一处代码错误及更正
    微软分布式机器学习工具包DMTK——初窥门径
    在2017年,如何将你的小米4刷上Windows 10 mobile?(后附大量图赏)
    第十周总结
    产品介绍 宿舍小助手
    博客园 之 “水王”
  • 原文地址:https://www.cnblogs.com/fangmin/p/2229924.html
Copyright © 2011-2022 走看看