CREATE PROCEDURE [ dbo ] . [ TranNumberToBigForDecrypt ]
(
@n_LowerMoney numeric( 15 , 2 ),
@v_TransType int ,
@RET VARCHAR ( 200 ) output
)
-- with ENCRYPTION
AS
/* *********************************
descript:解密exec sp_decrypt 'TranNumberToBig'
*/
Declare @v_LowerStr VARCHAR ( 200 ) -- 小写金额
Declare @v_UpperPart VARCHAR ( 200 )
Declare @v_UpperStr VARCHAR ( 200 ) -- 大写金额
Declare @startstr varchar ( 30 ) -- 点号前面的部分
Declare @endstr varchar ( 30 ) -- 点号后面部分
Declare @i_I int , @idx int , @e_I int , @i int
Declare @end_Upper varchar ( 100 ), @end_Part varchar ( 100 )
select @v_LowerStr = LTRIM ( RTRIM ( convert ( varchar ( 30 ), @n_LowerMoney ))) -- 变成字符串并删除数据左右空格
-- if(charindex('.',@v_LowerStr)>0)
begin
set @idx = charindex ( ' . ' , @v_LowerStr )
set @startstr = substring ( @v_LowerStr , 1 , @idx - 1 )
-- print @v_LowerStr
select @i_I = 1
select @v_UpperStr = ''
while ( @i_I <= len ( @startstr ))
begin
select @v_UpperPart = case substring ( @startstr , len ( @startstr ) - @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 ' 万 '
ELSE ''
END
select @v_UpperStr = @v_UpperPart + @v_UpperStr
select @i_I = @i_I + 1
end
-- if ( @v_TransType=0 )
-- begin
-- print @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
select @endstr = LTRIM ( RTRIM ( substring ( @v_LowerStr , @idx , len ( @v_LowerStr ) - @idx + 1 )))
select @e_I = 1
select @end_Part = ''
select @end_Upper = ''
while ( @e_I <= len ( @endstr ))
begin
select @end_Part = case substring ( @endstr , @e_I , 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
select @end_Upper = @end_Upper + @end_Part
select @e_I = @e_I + 1
end
set @i = len ( @end_Upper )
while ( @i > 0 )
begin
if ( right ( @end_Upper , 1 ) = ' 零 ' or right ( @end_Upper , 1 ) = ' 点 ' )
begin
select @end_Upper =left ( @end_Upper , @i - 1 )
select @i = @i - 1
end
else
break
end
-- select @Part=@v_UpperStr+@end_Upper
select @ret = @v_UpperStr + @end_Upper
end
GO
本文转自Sam Lin博客园博客,原文链接:http://www.cnblogs.com/samlin/archive/2008/02/20/1074821.html,如需转载请自行联系原作者