Lowercase capitalization amount

Source: Internet
Author: User
Tags lowercase min
Capital | amount | lowercase
It feels good to see an Oracle version of the lowercase capitalization amount function on the Web. Now turn it into a SQL Server version.

/********************************************************
Author: (birdie_7761@cmmail.com)
Version: 1.0
Date Created: 20020227
Modified time:
Features: Lowercase amounts are converted to uppercase
Parameters: N_lowermoney Lowercase Amount
V_transtype species--1:directly translate, 0:read it in words
Output: Uppercase Amount
********************************************************/
The CREATE FUNCTION dbo. L2U (@n_LowerMoney Numeric (15,2), @v_TransType int)
RETURNS VARCHAR () as
BEGIN
Declare @v_LowerStr VARCHAR (200)--Lowercase amount
Declare @v_UpperPart VARCHAR (200)
Declare @v_UpperStr VARCHAR (200)--Capital amount
Declare @i_I int

Set @v_LowerStr = LTRIM (RTRIM (ROUND (@n_LowerMoney, 2))--rounded to the specified precision and deletes the left and right spaces of the data
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 ' Yuan '
When ' 0 ' THEN ' 0 '
When ' 1 ' THEN '
When ' 2 ' THEN '
When ' 3 ' THEN ' three '
When ' 4 ' THEN ' Restaurant '
When ' 5 ' THEN ' Wu '
When ' 6 ' THEN ' land '
When ' 7 ' THEN ' qi '
When ' 8 ' THEN ' BA '
When ' 9 ' THEN ' nine '
End
+
Case @i_I
When 1 THEN ' min '
When 2 THEN ' Corner '
When 3 THEN '
When 4 THEN '
When 5 THEN ' pick '
When 6 THEN ' Bai '
When 7 THEN ' thousand '
When 8 THEN ' million '
When 9 THEN ' pick '
When ten THEN ' Bai '
When one THEN ' thousand '
When THEN ' billion '
When THEN ' picks '
When THEN ' Bai '
When THEN ' thousand '
When THEN ' million '
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, ' 0 Pick ', ' 0 ')
Set @v_UpperStr = REPLACE (@v_UpperStr, ' 0 bai ', ' 0 ')
Set @v_UpperStr = REPLACE (@v_UpperStr, ' 0 ', ' 0 ')
Set @v_UpperStr = REPLACE (@v_UpperStr, ' 000 ', ' 0 ')
Set @v_UpperStr = REPLACE (@v_UpperStr, ' 00 ', ' 0 ')
Set @v_UpperStr = REPLACE (@v_UpperStr, ' Certer ', ' whole ')
Set @v_UpperStr = REPLACE (@v_UpperStr, ' 0 minutes ', ' whole ')
Set @v_UpperStr = REPLACE (@v_UpperStr, ' 0 corners ', ' 0 ')
Set @v_UpperStr = REPLACE (@v_UpperStr, ' 0 yuan ', ' billion ')
Set @v_UpperStr = REPLACE (@v_UpperStr, ' billion zero million ', ' billion ')
Set @v_UpperStr = REPLACE (@v_UpperStr, ' 0 ', ' billion ')
Set @v_UpperStr = REPLACE (@v_UpperStr, ' 0 yuan ', ' million ')
Set @v_UpperStr = REPLACE (@v_UpperStr, ' million Zero ', ' million ')
Set @v_UpperStr = REPLACE (@v_UpperStr, ' 0 ', ' billion ')
Set @v_UpperStr = REPLACE (@v_UpperStr, ' 0 ', ' million ')
Set @v_UpperStr = REPLACE (@v_UpperStr, ' 0 yuan ', ' yuan ')
Set @v_UpperStr = REPLACE (@v_UpperStr, ' 00 ', ' 0 ')
End

--the treatment of the amount below one yuan
if (' Yuan ' = substring (@v_UpperStr, 1, 1))
Begin
Set @v_UpperStr = substring (@v_UpperStr, 2, (Len (@v_UpperStr)-1)
End

if (' 0 ' = substring (@v_UpperStr, 1, 1))
Begin
Set @v_UpperStr = substring (@v_UpperStr, 2, (Len (@v_UpperStr)-1)
End

if (' Corner ' = substring (@v_UpperStr, 1, 1))
Begin
Set @v_UpperStr = substring (@v_UpperStr, 2, (Len (@v_UpperStr)-1)
End

if (' min ' = substring (@v_UpperStr, 1, 1))
Begin
Set @v_UpperStr = substring (@v_UpperStr, 2, (Len (@v_UpperStr)-1)
End

if (' whole ' = substring (@v_UpperStr, 1, 1))
Begin
Set @v_UpperStr = ' 0 yuan int '
End
Return @v_UpperStr
End

Example:

SELECT dbo. L2U (56588441.111,0)

SELECT dbo. L2U (00.00,0)


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.