Results 1 to 5 of 5
  1. #1
    Join Date
    Feb 2010
    Posts
    2

    Unanswered: Migrate DIGITS() from DB2 to SQL Server

    Hi,

    I am working on a migration from DB2 to SQL, i found one of my UDFs using the DIGITS() function. Can anybody suggest me what is the alternative in SQL.

    Thank you...

  2. #2
    Join Date
    Jun 2003
    Location
    Toronto, Canada
    Posts
    5,516
    Provided Answers: 1
    Try CONVERT() or CAST()
    ---
    "It does not work" is not a valid problem statement.

  3. #3
    Join Date
    Feb 2010
    Posts
    2
    Thanks...any examples? and what would be the target data type when we do the conversion?

  4. #4
    Join Date
    May 2009
    Posts
    508
    Provided Answers: 1
    DIGITS returns a character string representation of a number with leading zeros. The length of the character string depends on the data type of the number.

    Small Integer returns a CHAR 5
    Large Integer returns a CHAR 10
    Big Integer returns a CHAR 19
    Decimal returns a CHAR x where X is the Precision of the Decimal.

    There isn't an exact equivalent in SQL. The closest single function is STR whose format is STR(value, length).

    If you have a Smallint value of 29 you would use STR(29,5).

    This will return a right justified number WITHOUT leading zeros.
    Code:
    DIGITS: 00029
    STR:       29
    If you can not work without leading zeros, you will need to do more work to add them.

  5. #5
    Join Date
    Jun 2003
    Location
    Toronto, Canada
    Posts
    5,516
    Provided Answers: 1
    Quote Originally Posted by nareshch View Post
    Thanks...any examples? and what would be the target data type when we do the conversion?
    So, you are planning to complete migration without ever opening the manual, aren't you? Good luck with that.
    ---
    "It does not work" is not a valid problem statement.

Tags for this Thread

Posting Permissions

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