Sunday, February 12, 2012

Convert digits to letters

I want to know if somebody have a fucntion to convert numbers to letters.
for Example: 56 to Fifty Six or
10,599 to Ten Thousand five hundred and ninety nine.
Please help me...
Radhamescheck this link
[url]http://www.novicksoftware.com/UDFofW/Vol2/T-SQL-UDF-Vol-2-Num-9-udf_Num_ToWords
.htm[/url]
-Omnibuzz
--
Please post ddls and sample data for your queries and close the thread if
you got the answer for your question.
"Radhames" wrote:

> I want to know if somebody have a fucntion to convert numbers to letters.
> for Example: 56 to Fifty Six or
> 10,599 to Ten Thousand five hundred and ninety nine.
> Please help me...
> Radhames|||Thanks omnibuzz
I going to implement this function in my database to convert numbers
to Spanish Words.
:)
"Omnibuzz" wrote:
> check this link
> [url]http://www.novicksoftware.com/UDFofW/Vol2/T-SQL-UDF-Vol-2-Num-9-udf_Num_ToWor
ds.htm[/url]
> --
> -Omnibuzz
> --
> Please post ddls and sample data for your queries and close the thread if
> you got the answer for your question.
>
> "Radhames" wrote:
>|||Don't forget to select the fact that he answered your question. Its nice to
see the little green check mark next to the question once it has been
answered.
:)
"Radhames" wrote:
> Thanks omnibuzz
> I going to implement this function in my database to convert numbers
> to Spanish Words.
> :)
> "Omnibuzz" wrote:
>|||> Don't forget to select the fact that he answered your question. Its nice
> to
> see the little green check mark next to the question once it has been
> answered.
What little green check mark?
Please keep in mind we're not all using a frilly web gui.|||A common function in report writers converts numbers into words so that
they can be used to print checks, legal documents and other reports.
This is not a common function in SQL products, nor is it part of the
standards.
A method for converting numbers into words using only standard SQL by
Stu Bloom follows. This was posted on 2002 Jan 02 on the SQL Server
Programming newsgroup.
First, create a table
CREATE TABLE NbrWords
(number INTEGER PRIMARY KEY,
word VARCHAR(30) NOT NULL);
Then populate it with the literal strings of all NbrWords from 0 to
999. Assuming that your range is 1 - 999,999,999 use the following
query; it should be obvious how to extend it for larger numbers and
fractional parts.
CASE WHEN :num < 1000
THEN (SELECT word FROM NbrWords
WHERE number = :num)
WHEN :num < 1000000
THEN (SELECT word FROM NbrWords
WHERE number = :num / 1000)
|| ' thousand '
|| (SELECT word FROM NbrWords
WHERE MOD (number = :num, 1000))
WHEN :num < 1000000000
THEN (SELECT word FROM NbrWords
WHERE number = :num / 1000000)
|| ' million '
|| (SELECT word FROM NbrWords
WHERE number = MOD((:num / 1000), 1000))
|| CASE WHEN MOD((:num / 1000), 1000) > 0
THEN ' thousand '
ELSE '' END
|| (SELECT word FROM NbrWords
WHERE number = MOD(:num, 1000))
END;

No comments:

Post a Comment