Home Database Mysql Tutorial SQL SERVER函数将人民币数字转换成大写形式

SQL SERVER函数将人民币数字转换成大写形式

Jun 07, 2016 pm 04:22 PM
server RMB function capital Replace with number

SQL SERVER函数将人民币数字转换成大写形式 CREATE FUNCTION [dbo].[f_num_chn] (@num numeric(14,5)) RETURNS varchar(100) WITH ENCRYPTION AS BEGIN DECLARE @n_data VARCHAR(20),@c_data VARCHAR(100),@n_str VARCHAR(10),@i int SET @n_data=RIGHT(S

   SQL SERVER函数将人民币数字转换成大写形式

  CREATE FUNCTION [dbo].[f_num_chn] (@num numeric(14,5))

  RETURNS varchar(100) WITH ENCRYPTION

  AS

  BEGIN

  DECLARE @n_data VARCHAR(20),@c_data VARCHAR(100),@n_str VARCHAR(10),@i int

  SET @n_data=RIGHT(SPACE(14)+CAST(CAST(ABS(@num*100) AS bigint) AS varchar(20)),,14)

  SET @c_data=''

  SET @i=1

  WHILE @i

  BEGIN

  SET @n_str=SUBSTRING(@n_data,@i,1)

  IF @n_str' '

  BEGIN

  IF not ((SUBSTRING(@n_data,@i,2)='00') or

  ((@n_str='0') and ((@i=4) or (@i=8) or (@i=12) or (@i=14))))

  SET @c_data=@c_data+SUBSTRING('零壹贰叁肆伍陆柒捌玖',CAST(@n_str AS int)+1,1)

  IF not ((@n_str='0') and (@i4) and (@i8) and (@i12))

  SET @c_data=@c_data+SUBSTRING('仟佰拾亿仟佰拾万仟佰拾圆角分',@i,1)

  IF SUBSTRING(@c_data,LEN(@c_data)-1,2)='亿万'

  SET @c_data=SUBSTRING(@c_data,1,LEN(@c_data)-1)

  END

  SET @i=@i+1

  END

  IF @num

  SET @c_data='(负数)'+@c_data

  IF @num=0

  SET @c_data='零圆'

  IF @n_str='0'

  SET @c_data=@c_data+'整'

  RETURN(@c_data)

  END

  SQL SERVER函数将人民币数字转换成大写形式

  闲着也是闲着,欢迎大家多提宝贵意见

  --阿拉伯数字转中文大写数字

  Create function NToCC(@n int)

  returns varchar(2)

  as

  begin

  declare @s varchar(2)

  if @n=0

  set @s=''零''

  if @n=1

  set @s=''壹''

  if @n=2

  set @s=''贰''

  if @n=3

  set @s=''叁''

  if @n=4

  set @s=''肆''

  if @n=5

  set @s=''伍''

  if @n=6

  set @s=''陆''

  if @n=7

  set @s=''柒''

  if @n=8

  set @s=''捌''

  if @n=9

  set @s=''玖''

  return @s

  end

  --可支持到上亿

  Create function numbertoChineseBigString(@m money)

  returns varchar(255)

  begin

  declare @i varchar(255)

  declare @f varchar(255)

  declare @r varchar(255)

  declare @s varchar(255)

  set @s=convert(varchar(255),@m)

  if charindex(''.'',@s)>0

  begin

  set @i=substring(@s,1,charindex(''.'',@s)-1)

  set @f=substring(@s,charindex(''.'',@s)+1,len(@s))

  end

  else

  set @i=@s

  set @r=''''

  declare @k int

  set @k=len(@i)

  while @k>=1

  begin

  --最多9位

  if @k=9

  set @r=@r+

  dbo.NToCC(convert(int,substring(REVERSE(@i),@k,1)))

  --@i

  +''亿''

  if @k=8

  set @r=@r+dbo.NToCC(convert(int,substring(REVERSE(@i),@k,1)))+''千''

  if @k=7

  set @r=@r+dbo.NToCC(convert(int,substring(REVERSE(@i),@k,1)))+''佰''

  if @k=6

  set @r=@r+dbo.NToCC(convert(int,substring(REVERSE(@i),@k,1)))+''拾''

  if @k=5

  set @r=@r+dbo.NToCC(convert(int,substring(REVERSE(@i),@k,1)))+''万''

  if @k=4

  set @r=@r+dbo.NToCC(convert(int,substring(REVERSE(@i),@k,1)))+''千''

  if @k=3

  set @r=@r+dbo.NToCC(convert(int,substring(REVERSE(@i),@k,1)))+''佰''

  if @k=2

  set @r=@r+dbo.NToCC(convert(int,substring(REVERSE(@i),@k,1)))+''拾''

  if @k=1

  set @r=@r+dbo.NToCC(convert(int,substring(REVERSE(@i),@k,1)))+''元''

  set @k=@k-1

  end

  if convert(float,@f)=0

  set @r=@r+''整''

  else

  begin

  if substring(@s,1,1)>''''

  set @r=@r+dbo.NToCC(convert(int,substring(@f,1,1)))+''角''

  if substring(@s,2,1)>''''

  set @r=@r+dbo.NToCC(convert(int,substring(@f,2,1)))+''分''

  end

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Tips for dynamically creating new functions in golang functions Tips for dynamically creating new functions in golang functions Apr 25, 2024 pm 02:39 PM

Go language provides two dynamic function creation technologies: closure and reflection. closures allow access to variables within the closure scope, and reflection can create new functions using the FuncOf function. These technologies are useful in customizing HTTP routers, implementing highly customizable systems, and building pluggable components.

Considerations for parameter order in C++ function naming Considerations for parameter order in C++ function naming Apr 24, 2024 pm 04:21 PM

In C++ function naming, it is crucial to consider parameter order to improve readability, reduce errors, and facilitate refactoring. Common parameter order conventions include: action-object, object-action, semantic meaning, and standard library compliance. The optimal order depends on the purpose of the function, parameter types, potential confusion, and language conventions.

How to write efficient and maintainable functions in Java? How to write efficient and maintainable functions in Java? Apr 24, 2024 am 11:33 AM

The key to writing efficient and maintainable Java functions is: keep it simple. Use meaningful naming. Handle special situations. Use appropriate visibility.

Complete collection of excel function formulas Complete collection of excel function formulas May 07, 2024 pm 12:04 PM

1. The SUM function is used to sum the numbers in a column or a group of cells, for example: =SUM(A1:J10). 2. The AVERAGE function is used to calculate the average of the numbers in a column or a group of cells, for example: =AVERAGE(A1:A10). 3. COUNT function, used to count the number of numbers or text in a column or a group of cells, for example: =COUNT(A1:A10) 4. IF function, used to make logical judgments based on specified conditions and return the corresponding result.

C++ Function Exception Advanced: Customized Error Handling C++ Function Exception Advanced: Customized Error Handling May 01, 2024 pm 06:39 PM

Exception handling in C++ can be enhanced through custom exception classes that provide specific error messages, contextual information, and perform custom actions based on the error type. Define an exception class inherited from std::exception to provide specific error information. Use the throw keyword to throw a custom exception. Use dynamic_cast in a try-catch block to convert the caught exception to a custom exception type. In the actual case, the open_file function throws a FileNotFoundException exception. Catching and handling the exception can provide a more specific error message.

Things to note when Golang functions receive map parameters Things to note when Golang functions receive map parameters Jun 04, 2024 am 10:31 AM

When passing a map to a function in Go, a copy will be created by default, and modifications to the copy will not affect the original map. If you need to modify the original map, you can pass it through a pointer. Empty maps need to be handled with care, because they are technically nil pointers, and passing an empty map to a function that expects a non-empty map will cause an error.

Realme GT Neo6 is scheduled to be released on May 9th! The first AI digital human conference in the computer industry Realme GT Neo6 is scheduled to be released on May 9th! The first AI digital human conference in the computer industry May 08, 2024 pm 12:49 PM

On May 7, our mobile phone manufacturer officially announced that our company’s GTNeo6 launch conference is scheduled for May 9. GTNoe6 is positioned as a "performance storm", aiming to stir up the mid-range machine situation. In addition, this conference will also be the first AI digital human conference in the mobile phone industry. At that time, Realme Vice President, Global Marketing President, and China President Xu Qi will appear at the press conference in the form of a digital human. Digital man Xu Qi According to the official introduction, Realme GTNoe6, codenamed "Hurricane", is faster and stronger. It will challenge the strongest third-generation Snapdragon 8s flagship and the strongest product in its class. Recently, the Realme GTNeo6 was found to be directly on the e-commerce platform. Some core configurations were exposed, showing that the machine is not only equipped with a Snapdragon 8s processor, but also supports 120W flash charging.

The magic formula for PHP function execution efficiency The magic formula for PHP function execution efficiency Apr 23, 2024 pm 10:21 PM

To solve the problem of low efficiency of PHP function execution, you can follow the following magic formula: reduce the number of parameters, use parameter passing by reference, shorten the length of the function body, and reduce the depth of function calls. Practical example: Passing parameters by reference can significantly improve performance. Best practices include: avoiding unnecessary calls, using caching, analyzing performance bottlenecks, and following coding standards.

See all articles