Results 1 to 3 of 3
  1. #1
    Join Date
    Oct 2003
    Posts
    7

    Question Unanswered: Help! Scalar Function to Strip last Digit

    Hello, I'm new to the DB2 SQL Syntax.

    I am using DB2 Connect to query our AS400 database.
    I am trying to select a numeric column and strip the last digit.

    I've been playing with the scalar functions, but still do not understand which one to use to strip that last digit, which is serving as a check digit and must be stripped to perform a join correctly.

    I need a simple SQL statement as one of the other tools I am using will not accept variables, etc.

    The field is left padded with 0's so 281 = 0000281, datatype is Numeric 7,0
    Any suggestions?

    Thank you,

    S.OLIVER

    DB2 Connect Enterprise Edition
    DB2 v8.1.1.0
    FixPak 0
    AIX 5.2

  2. #2
    Join Date
    Nov 2003
    Location
    Netherlands
    Posts
    96
    Quote Originally Posted by soliver


    The field is left padded with 0's so 281 = 0000281, datatype is Numeric 7,0
    Any suggestions?
    Hi,
    This works on DB2 8.2 on Windows and doesn't depend on the length of the column c:

    select substr(digits(c),1,length(digits(c))-1) from a

    Hope this helps

  3. #3
    Join Date
    Oct 2003
    Posts
    7

    Smile Worked!

    I just tried the query and it works.
    Thanks!

Posting Permissions

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