SQL Server Chinese capital amount Conversion Function

Source: Internet
Author: User
In order to be able to directly enter an upper-case amount in the report, I wrote the SQL server function. copy the following code to the SQL Server Query analyzer and generate the User-Defined Function usf_ChineseCost. you can call this function in the query statement to output an upper-case amount. SQL Server capital amount CREATEFUNCTIONusf_Ch

In order to directly enter the capital amount in the report, I wrote the SQL Server function. copy the following code to the SQL Server Query analyzer and generate the User-Defined Function usf_ChineseCost. you can call this function in the query statement to output an upper-case amount. SQL Server Chinese capital amount CREATE FUNCTION usf_Ch

In order to directly enter the capital amount in the report, I wrote the SQL Server function. copy the following code to the SQL Server Query analyzer and generate the User-Defined Function usf_ChineseCost. you can call this function in the query statement to output an upper-case amount.

SQL Server Chinese amount capital amount
Create function usf_ChineseCost (@ Cost float) RETURNS varchar (50) AS ---- capital amount ---- BEGIN declare @ returnStr varchar (50) if (@ Cost> = 1000000000) begin set @ returnStr = '######### 'Return @ returnStr end set @ returnStr = '000000' set @ returnStr = right (@ returnStr + convert (varchar, convert (decimal (11,2), round (@ cost, 2), 12) set @ returnStr = replace (@ returnStr, '0', '0 ') set @ returnStr = replace (@ returnStr, '1', 'yi') set @ returnStr = replace (@ returnStr, '2', 'er ') set @ returnStr = replace (@ returnStr, '3', 'san') set @ returnStr = replace (@ returnStr, '4', 'sha ') set @ returnStr = replace (@ returnStr, '5', 'wo') set @ returnStr = replace (@ returnStr, '6', 'loan ') set @ returnStr = replace (@ returnStr, '7', 'failed') set @ returnStr = replace (@ returnStr, '8', 'failed ') set @ returnStr = replace (@ returnStr, '9', 'failed') set @ returnStr = @ returnStr + 'shard' set @ returnStr = stuff (@ returnStr, len (@ returnStr)-1, 0, 'angular ') set @ returnStr = replace (@ returnStr ,'. ', 'meta') set @ returnStr = stuff (@ returnStr, len (@ returnStr)-5, 0, 'pick') set @ returnStr = stuff (@ returnStr, len (@ returnStr)-7,0, 'ba') set @ returnStr = stuff (@ returnStr, len (@ returnStr)-9, 0, 'kilo ') set @ returnStr = stuff (@ returnStr, len (@ returnStr)-11, 0, 'wan') set @ returnStr = stuff (@ returnStr, len (@ returnStr)-13, 0, 'select') set @ returnStr = stuff (@ returnStr, len (@ returnStr)-15, 0, 'bai') set @ returnStr = stuff (@ returnStr, len (@ returnStr) -17,0, 'kil') set @ returnStr = stuff (@ returnStr, len (@ returnStr)-19,0, '') set @ returnStr = replace (@ returnStr, '20140901', '0') set @ returnStr = replace (@ returnStr, '0', '0') set @ returnStr = replace (@ returnStr, '0100 ', 'zero') set @ returnStr = replace (@ returnStr, 'zero restart', 'zero ') set @ returnStr = replace (@ returnStr, 'zero zero 0', 'zero ') set @ returnStr = replace (@ returnStr, 'zero 1', 'zero ') set @ returnStr = replace (@ returnStr, '123456', 'wan ') set @ returnStr = replace (@ returnStr, '0 meta', 'meta') set @ returnStr = replace (@ returnStr, '0 ange', '0 ') set @ returnStr = replace (@ returnStr, 'zero point', '') while left (@ returnStr, 1) = '0' Begin set @ returnStr = right (@ returnStr, len (@ returnStr)-1) end if (left (@ returnStr, 1) = 'wan') begin set @ returnStr = right (@ returnStr, len (@ returnStr) -1) end if (left (@ returnStr, 1) = 'meta') begin set @ returnStr = right (@ returnStr, len (@ returnStr)-1) end while left (@ returnStr, 1) = '0' Begin set @ returnStr = right (@ returnStr, len (@ returnStr)-1) end while right (@ returnStr, 1) = '0' Begin set @ returnStr = left (@ returnStr, len (@ returnStr)-1) end set @ returnStr = replace (@ returnStr, 'billionaire, 'yi0 ') set @ returnStr = replace (@ returnStr, 'zero meta', 'meta') set @ returnStr = replace (@ returnStr, 'zero 0', 'zero ') set @ returnStr = replace (@ returnStr, '0', '0') if (@ returnStr = '') begin set @ returnStr = 'zero meta' end if (right (@ returnStr, 1) = 'meta ')) begin set @ returnStr = @ returnStr + 'Integral 'end return @ returnStrEND

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.