Capital | function | amount | lowercase | convert CREATE FUNCTION [dbo]. [F_num_eng] (@num numeric (15,2))
RETURNS varchar () with encryption
As
BEGIN
--all rights reserved. Pbsql
DECLARE @i int, @hundreds int, @tenth int, @one int
DECLARE @thousand int, @million int, @billion int
DECLARE @numbers varchar, @s varchar, @result varchar (400)
SET @numbers = ' One Two three four five '
+ ' Six seven eight nine Ten '
+ ' Eleven twelve thirteen fourteen fifteen '
+ ' Sixteen seventeen Eighteen nineteen '
+ ' Twenty Thirty forty fifty '
+ ' Sixty Seventy Eighty Ninety '
SET @s=right (' 000000000000000 ' +cast (@num as varchar (15)), 15)
Set @billion =cast (SUBSTRING (@s,1,3) as int)--divides 12-bit integers into 4 segments: 1 billion, million, Thousand, Bashing
SET @million =cast (SUBSTRING (@s,4,3) as int)
SET @thousand =cast (SUBSTRING (@s,7,3) as int)
SET @result = '
SET @i=0
While @i<=3
BEGIN
SET @hundreds =cast (SUBSTRING (@s,@i*3+1,1) as int)--hundred 0-9
SET @tenth =cast (SUBSTRING (@s,@i*3+2,1) as int)
SET @one = (case @tenth when 1 THEN ' 0 end) +cast (SUBSTRING (@s,@i*3+3,1) as int)--Single-digit 0-19
SET @tenth = (case when @tenth <=1 THEN 0 ELSE @tenth End)--10 digits 0, 2-9
IF (@i=1 and @billion >0 and (@million >0 or @thousand >0 or @hundreds >0)) or
(@i=2 and (@billion >0 or @million >0) and (@thousand >0 or @hundreds >0)) or
(@i=3 and (@billion >0 or @million >0 or @thousand >0) and (@hundreds >0))
SET @result = @result + ', '--the Hundred is not 0 and each segment is joined by a connector.
IF (@i=3 and (@billion >0 or @million >0 or @thousand >0) and (@hundreds =0 and (@tenth >0 or @one >0)))
SET @result = @result + ' and '--the Hundred is 0 plus the connector and
IF @hundreds >0
SET @result = @result +rtrim (SUBSTRING (@numbers, @hundreds *10-9,10)) + ' hundred '
IF @tenth >=2 and @tenth <=9
BEGIN
IF @hundreds >0
SET @result = @result + ' and '
SET @result = @result +rtrim (SUBSTRING (@numbers, @tenth *10+171,10))
End
IF @one >=1 and @one <=19
BEGIN
IF @tenth >0
SET @result = @result + '-'
ELSE
IF @hundreds >0
SET @result = @result + ' and '
SET @result = @result +rtrim (SUBSTRING (@numbers, @one *10-9,10))
End
IF @i=0 and @billion >0
SET @result = @result + ' billion '
IF @i=1 and @million >0
SET @result = @result + ' million '
IF @i=2 and @thousand >0
SET @result = @result + ' thousand '
SET @i=@i+1
End
IF SUBSTRING (@s,14,2) <> ' 00 '
BEGIN
SET @result = @result + ' point '
IF SUBSTRING (@s,14,1) = ' 0 '
SET @result = @result + ' zero '
ELSE
SET @result = @result +rtrim (SUBSTRING (@numbers, CAST (SUBSTRING (@s,14,1) as int) *10-9,10)
IF SUBSTRING (@s,15,1) <> ' 0 '
SET @result = @result + ' +rtrim (SUBSTRING (@numbers, CAST (SUBSTRING (@s,15,1) as int) *10-9,10))
End
Return (@result)
End
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.