Results 1 to 3 of 3

Thread: TSQL help neede for converting numbers

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Feb 2002
    Posts
    28

    Question TSQL help neede for converting numbers

    Hi vb experts!

    I am using vb6 + sql2000. How can I convert a number (integer or decimal) to CHAR format, where the length is 12 and I have to fill the empty characters with 0s. Ex: 128 - 000000128,00 or 1223.2 - 000001223,20. I can write an algorithm to do that, but I'm pretty sure that there are easier ways. Thx for your help!

  2. #2
    Junior Member RvA's Avatar
    Join Date
    Oct 2002
    Location
    USA
    Posts
    19
    Hello yo-vb

    Ok I would do that with a format statement.

    VB Code:
    1. Private Function FormatNum(ByVal iNum As Integer) As String
    2.   Dim sRtn As String
    3.  
    4.   sRtn = Format(iNum, "000000000000")
    5.   FormatNum = sRtn
    6.  
    7. End Function

    I think that would be the easiest way to handle that one.

    Hope that helps a little.
    Best,

    Roger

    VB6.0 SR5 & VB.Net Pro
    -----------------------------------------------
    Do or do not, there is no try!

  3. #3
    PowerPoster BruceG's Avatar
    Join Date
    May 2000
    Location
    New Jersey (USA)
    Posts
    2,657
    He's looking for the T-SQL way to do it. Try this:
    SELECT RIGHT('000000000000' + CONVERT(VARCHAR(12), YourNumField), 12) AS FormattedField FROM YourTable etc. etc.
    "It's cold gin time again ..."

    Check out my website here.

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