小寫金額轉換成大寫 sql server

2021-04-14 20:41:57 字數 4525 閱讀 9241

if

exists

(select

*from

dbo.sysobjects

where

id =

object_id(n'

[dbo].[l2u]')

andxtype

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

intset

@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

1then'分

'when

2then'角

'when

3then

''when

4then

''when

5then'拾

'when

6then'佰

'when

7then'仟

'when

8then'萬

'when

9then'拾

'when

10then'佰

'when

11then'仟

'when

12then'億

'when

13then'拾

'when

14then'佰

'when

15then'仟

'when

16then'萬

'else

''end

set@v_upperstr

=@v_upperpart

+@v_upperstr

set@i_i

=@i_i+1

endif( 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))endif( '

零'=substring

(@v_upperstr,1

,1))begin

set@v_upperstr

=substring

(@v_upperstr,2

,(len

(@v_upperstr) -

1))endif( '

角'=substring

(@v_upperstr,1

,1))begin

set@v_upperstr

=substring

(@v_upperstr,2

,(len

(@v_upperstr) -

1))endif( '

分'=substring

(@v_upperstr,1

,1))begin

set@v_upperstr

=substring

(@v_upperstr,2

,(len

(@v_upperstr) -

1))endif('

整'=substring

(@v_upperstr,1

,1))begin

set@v_upperstr='

零元整'

endreturn

@v_upperstr

endgo

select

dbo.l2u(

12.93,1

),dbo.l2u(

12.93,0

)

小寫金額轉換成大寫

原作在sql 2000中有一些問題。修正錯誤並在sql 2000中執行通過。set nocount on select v lowerstr ltrim rtrim str n lowermoney,20,2 四捨五入為指定的精度並刪除資料左右空格 select i i 1 select v upp...

小寫金額轉換成大寫 sql server

if exists select from dbo.sysobjects where id object id n dbo l2u andxtype in n fn n if n tf drop function dbo l2u go create function dbo.l2u n lowerm...

Java將小寫金額轉換成大寫

工作中遇到金額小寫轉大寫的需求。由於現成的工具包沒有找到此功能。最後搜到 如下 public class test public static string change double v long l math.round v 100 if l 0 string strvalue l i用來控制數...