程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 數據庫知識 >> SqlServer數據庫 >> 關於SqlServer >> 小寫轉大寫金額

小寫轉大寫金額

編輯:關於SqlServer

在網上見到一個Oracle的版本的小寫轉大寫金額的函數,感覺還不錯現在把它轉成SQL Server版本。

/********************************************************
作者:([email protected])
版本:1.0
創建時間:20020227
修改時間:
功能:小寫金額轉換成大寫
參數:n_LowerMoney 小寫金額
v_TransType 種類 -- 1: directly translate, 0: read it in Words
輸出:大寫金額
********************************************************/
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 '分'
&


您正在看的SQLserver教程是:小寫轉大寫金額。nbsp; 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(


您正在看的SQLserver教程是:小寫轉大寫金額。@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

例子:

select dbo.L2U(56588441.111,0)

select dbo.L2U(00.00,0)

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved