If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > DB2 > Help! Scalar Function to Strip last Digit

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 01-11-05, 17:43
soliver soliver is offline
Registered User
 
Join Date: Oct 2003
Posts: 7
Question 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
Reply With Quote
  #2 (permalink)  
Old 01-11-05, 18:10
GertK GertK is offline
Registered User
 
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
Reply With Quote
  #3 (permalink)  
Old 01-11-05, 18:29
soliver soliver is offline
Registered User
 
Join Date: Oct 2003
Posts: 7
Smile Worked!

I just tried the query and it works.
Thanks!
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On