Results 1 to 13 of 13

Thread: How to change numbers to words in SQL?

  1. #1

    Thread Starter
    Frenzied Member moinkhan's Avatar
    Join Date
    Jun 2000
    Location
    Karachi, Pakistan
    Posts
    2,011

    How to change numbers to words in SQL?

    I want to display the numbers in Words in SQL

    e.g. 1204 should be displayed as One thousand and four..

    Any idea?

  2. #2
    PowerPoster Keithuk's Avatar
    Join Date
    Jan 2004
    Location
    Staffordshire, England
    Posts
    2,236
    Try One Thousand Two Hundred and Four.

  3. #3
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170
    You write code for it. Google is your friend, you should find stuff.

  4. #4

    Thread Starter
    Frenzied Member moinkhan's Avatar
    Join Date
    Jun 2000
    Location
    Karachi, Pakistan
    Posts
    2,011
    I found this statement and it's working fine.. can somebody explain it to me?

    Select to_char(to_date(to_char(99999,'999999999','J'),'JSP') From Dual

  5. #5
    Banned jhermiz's Avatar
    Join Date
    Jun 2002
    Location
    Antarctica
    Posts
    2,492
    Originally posted by moinkhan
    I found this statement and it's working fine.. can somebody explain it to me?

    Select to_char(to_date(to_char(99999,'999999999','J'),'JSP') From Dual
    Try BOL

  6. #6

    Thread Starter
    Frenzied Member moinkhan's Avatar
    Join Date
    Jun 2000
    Location
    Karachi, Pakistan
    Posts
    2,011
    BOL?

  7. #7
    Hyperactive Member AvisSoft's Avatar
    Join Date
    Sep 2002
    Location
    Chandigarh
    Posts
    459
    Originally posted by moinkhan
    I found this statement and it's working fine.. can somebody explain it to me?

    Select to_char(to_date(to_char(99999,'999999999','J'),'JSP') From Dual
    Hi!

    You mean that it works ? And you're using VB right ? I made a stupid non working function for this...and it was not perfect then i stopped working on that. If this works then why should i have another stupid function.

    Can you explain more how it works please ?

    Thanks!
    Tapan Bhanot,
    CEO, Avis Software.
    Website: www.avissoftware.com

  8. #8
    Banned jhermiz's Avatar
    Join Date
    Jun 2002
    Location
    Antarctica
    Posts
    2,492
    Originally posted by AvisSoft
    Hi!

    You mean that it works ? And you're using VB right ? I made a stupid non working function for this...and it was not perfect then i stopped working on that. If this works then why should i have another stupid function.

    Can you explain more how it works please ?

    Thanks!
    Do you have client tools SQL installed ?

    DO you have a copy of BOL ? Books online...

    Refer to that it gives great examples and explanations of what you are trying to do.

  9. #9
    Hyperactive Member AvisSoft's Avatar
    Join Date
    Sep 2002
    Location
    Chandigarh
    Posts
    459
    Where do i get copy of BOL ?
    Tapan Bhanot,
    CEO, Avis Software.
    Website: www.avissoftware.com

  10. #10
    Banned jhermiz's Avatar
    Join Date
    Jun 2002
    Location
    Antarctica
    Posts
    2,492
    Originally posted by AvisSoft
    Where do i get copy of BOL ?

    It comes wiht client and tools
    or go here:

    http://www.microsoft.com/sql/techinf...2000/books.asp

  11. #11

    Thread Starter
    Frenzied Member moinkhan's Avatar
    Join Date
    Jun 2000
    Location
    Karachi, Pakistan
    Posts
    2,011
    I haven't checked this with VB... although because it is the standard SQL Function.. should work with VB...

    The explanation is easy...
    to_char(to_date(to_char(99999,'999999999','J'),'JSP')

    in this the innermost to_char is found useless... so u can also remove that. now this reads

    to_char(to_date(12345,'J'),'JSP')

    the to_date function changes this number into Julian Date format..... and then to_char function uses J(Julian format) SP(Spell) switches to convert this Julian date into words...
    I did it on SQL Plus environment in Oracle.. haven't yet checked with VB... but i hope it should also work there..

    Originally posted by AvisSoft
    Hi!

    You mean that it works ? And you're using VB right ? I made a stupid non working function for this...and it was not perfect then i stopped working on that. If this works then why should i have another stupid function.

    Can you explain more how it works please ?

    Thanks!

  12. #12
    Hyperactive Member Vishalgiri's Avatar
    Join Date
    Oct 2003
    Location
    India
    Posts
    345
    Hence it is a Classic Visual basic Forum

    I suggest you to make a Function which returns a string and arguments passed to function is integer.

    and in that function first typecast that integer to string and find its length then using right() take first integer to the right and then a select case if it is 1 then replace 1 with "One" Proceeding in this way the second chr from right if it is 2 then replace it with "Twenty " for third chr if it is 1 then replace it with One hundred.......

    Make some this kind of logic . . .

  13. #13

    Thread Starter
    Frenzied Member moinkhan's Avatar
    Join Date
    Jun 2000
    Location
    Karachi, Pakistan
    Posts
    2,011
    I did it with VB a long ago.... but now i needed a pure SQL solution.... n i got that by myself.. thanx for your suggestion..

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width