|
The landlord then refers to this:
--Create function
Create Function ChangeBigSmall(@ChangeMoney money)
Returns VarChar(100) AS
Begin
Declare @String1 char(20)
Declare @String2 char(30)
Declare @String4 Varchar(100)
Declare @String3 Varchar(100) - the value taken from the original A value
Declare @i int - loop variable
Declare @J Int - The value of A multiplied by the string length of 100
Declare @Ch1 Varchar(100) - Chinese reading of numbers
Declare @Ch2 Varchar(100) - Chinese character reading of digits
Declare @Zero Int - used to calculate how many consecutive zeros
Declare @ReturnValue VarChar(100)
Select @ReturnValue =''
Select @String1 ='Zero One Two Three Lu Wu Qiu Jiu Jiu'
Select @ String2 = 'Wan Qian Bai picked up 1,000 billion Bai Bai Qian Wan pick up ten-dollar arc minutes'
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-indicates that the standard is not zero
End
Else
Begin
If (@Zero = 0) Or (@i = @J-9) Or (@i = @J-5) Or (@i = @J-1)
Select @Ch1 ='zero'
Else
Select @Ch1 =''
Select @Zero = @Zero + 1 - indicates that the standard is 0
The
--If the converted value needs to be expanded, then the value of the following expression I needs to be changed.
Select @Ch2 =''
The
If @i = @J-10
Begin
Select @Ch2 ='Billion'
Select @Zero = 0
End
If @i = @J-6
Begin
Select @Ch2 ='Wan'
Select @Zero = 0
End
The
If @i = @J-2
Begin
Select @Ch2 ='Yuan'
Select @Zero = 0
End
The
If @i = @J
Select @Ch2 ='Full'
End
Select @ReturnValue = @ReturnValue + @Ch1 + @Ch2
Select @i = @i+1
End
- Finally remove the extra zeros
If CharIndex('仟仟',@ReturnValue) <> 0
Select @ReturnValue = Replace(@ReturnValue,'仟仟','仟')
If CharIndex('百百',@ReturnValue) <> 0
Select @ReturnValue = Replace(@ReturnValue,'Baibai','Bai')
If CharIndex('Zero Yuan', @ReturnValue) <> 0
Select @ReturnValue = Replace(@ReturnValue,'zero yuan','yuan')
If CharIndex('Zero Thousand',@ReturnValue) <> 0
Select @ReturnValue = Replace(@ReturnValue,'zero ten thousand','ten thousand')
If CharIndex('Zero Billion', @ReturnValue) <> 0
Select @ReturnValue = Replace(@ReturnValue,'Zero Billion','Billion')
If CharIndex('Zero integer',@ReturnValue) <> 0
Select @ReturnValue = Replace(@ReturnValue,'zero integer','integer')
If CharIndex('Zero Bai',@ReturnValue) <> 0
Select @ReturnValue = Replace(@ReturnValue,'Zero Bai','Zero')
If CharIndex('零仟',@ReturnValue) <> 0
Select @ReturnValue = Replace(@ReturnValue,'零仟','zero')
If CharIndex('元元',@ReturnValue) <> 0
Select @ReturnValue = Replace(@ReturnValue,'元元','元')
Return @ReturnValue
End
go
--Call functions
select dbo.ChangeBigSmall(1000101.567)
go
--Delete function
drop function ChangeBigSmall
--View Results
/*
One hundred and one hundred and one hundred and one yuan
*/ |
|