create procedure atoc
@changemoney money
asset nocount on
declare @string1 char(20)
declare @string2 char(30)
declare @string4 varchar(100)
declare @string3 varchar(100) --從原a值中取出的值
declare @i int --迴圈變數
declare @j int --a的值乘以100的字串長度
declare @ch1 varchar(100) --數字的漢語讀法
declare @ch2 varchar(100) --數字位的漢字讀法
declare @zero int --用來計算連續有幾個零
declare @returnvalue varchar(100)
select @returnvalue = ''
select @string1 = '零壹貳叄肆伍陸柒捌玖'
select @string2 = '萬仟佰拾億仟佰拾萬仟佰拾元角分'
select @string4 = cast(@changemoney*100 as int)
select @j=len(cast((@changemoney*100) as int))
select @string2=right(@string2,@j)
select @i = 1
while @i<= @j begin
select @string3 = substring(@string4,@i,1)
if @string3<>'0' begin
select @ch1 = substring(@string1, cast(@string3 as int) + 1, 1)
select @ch2 = substring(@string2, @i, 1)
select @zero = 0 --表示本位不為零
endelse begin
if (@zero = 0) or (@i = @j - 9) or (@i = @j - 5) or (@i = @j - 1)
select @ch1 = '零'
else
select @ch1 = ''
select @zero = @zero + 1 --表示本位為0
--如果轉換的數值需要擴大,那麼需改動以下表示式 i 的值。
select ch2 = ''
if @i = @j - 10 begin
select @ch2 = '億'
select @zero = 0
endif @i = @j - 6 begin
select @ch2 = '萬'
select @zero = 0
endif @i = @j - 2 begin
select @ch2 = '元'
select @zero = 0
endif @i = @j
select @ch2 = '整'
end
select @returnvalue = @returnvalue + @ch1 + @ch2
select @i = @i+1
end--最後將多餘的零去掉
if charindex('仟仟',@returnvalue) <> 0
select @returnvalue = replace(@returnvalue, '仟仟', '仟')
if charindex('佰佰',@returnvalue) <> 0
select @returnvalue = replace(@returnvalue, '佰佰', '佰')
if charindex('零元',@returnvalue) <> 0
select @returnvalue = replace(@returnvalue, '零元', '元')
if charindex('零萬',@returnvalue) <> 0
select @returnvalue = replace(@returnvalue, '零萬', '萬')
if charindex('零億',@returnvalue) <> 0
select @returnvalue = replace(@returnvalue, '零億', '億')
if charindex('零整',@returnvalue) <> 0
select @returnvalue = replace(@returnvalue, '零整', '整')
if charindex('零佰',@returnvalue) <> 0
select @returnvalue = replace(@returnvalue, '零佰', '零')
if charindex('零仟',@returnvalue) <> 0
select @returnvalue = replace(@returnvalue, '零仟', '零')
if charindex('元元',@returnvalue) <> 0
select @returnvalue = replace(@returnvalue, '元元', '元')
select @returnvalue
go
阿拉伯數字金額轉換為中文大寫
set ansi nulls on goset quoted identifier on gocreate procedure dbo moneytochinese 阿拉伯數字金額轉換為中文大寫 changemoney money returndaxie varchar 50 output asse...
金額阿拉伯數字轉換為中文的儲存過程
create procedure atoc changemoney money asset nocount on declare string1 char 20 declare string2 char 30 declare string4 varchar 100 declare string3 v...
金額阿拉伯數字轉換為中文的儲存過程
create procedure atoc changemoney money as set nocount on declare string1 char 20 declare string2 char 30 declare string4 varchar 100 declare string3 ...