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 > Partial numeric match

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 07-01-09, 12:04
art500 art500 is offline
Registered User
 
Join Date: Jul 2009
Posts: 1
Partial numeric match

I need help on matching numeric fields based on a partial match.

I have two tables that match 9-digits in a 12-digit numeric field.

Example:

Table 1
123456789

Table 2
999123456789

I need to match on the last 9 digits. Any suggestions?
Reply With Quote
  #2 (permalink)  
Old 07-01-09, 12:46
ARWinner ARWinner is offline
Registered User
 
Join Date: Jan 2003
Posts: 3,575
Try using the MOD function.

Andy
Reply With Quote
  #3 (permalink)  
Old 07-01-09, 13:48
Cougar8000 Cougar8000 is offline
Registered User
 
Join Date: Nov 2005
Location: IL
Posts: 554
Not sure if MOD is a right approach here as it will return the remainder for the first argument.

convert to CHAR; substr the last 9; then match. Be ready for performance dive.

Then fix the data.
__________________
--
IBM Certified DBA on DB2 for Linux, UNIX, and Windows

DB2 v9.1.0.2 os 5.3.0.0
Reply With Quote
  #4 (permalink)  
Old 07-01-09, 14:24
stolze stolze is offline
Registered User
 
Join Date: Jan 2007
Location: Jena, Germany
Posts: 2,662
If you use MOD 1000000000, you effectively retain only the last 9 digits. So the conversion to CHAR+substr will be slower for sure because much more processing is involved compared to a simple CPU instruction.
__________________
Knut Stolze
IBM DB2 Analytics Accelerator
IBM Germany Research & Development
Reply With Quote
  #5 (permalink)  
Old 07-01-09, 14:26
Ax238 Ax238 is offline
Registered User
 
Join Date: May 2009
Posts: 257
You could also just use INT(RIGHT(Field, 9)) on the match, but I'd agree with stolze.

Last edited by Ax238; 07-01-09 at 14:29.
Reply With Quote
  #6 (permalink)  
Old 07-01-09, 14:40
Cougar8000 Cougar8000 is offline
Registered User
 
Join Date: Nov 2005
Location: IL
Posts: 554
Thanks for clarifying Knut. Never used MOD before. Built a small table and tested and it sure works as a charm.

Should stop questioning Andy

Code:
db2 "select col1, mod(col1, 1000000000) from schema.c"     

COL1                 2                   
-------------------- --------------------
          1234567890            234567890
         23456789023            456789023
          3534267351            534267351
           400000000            400000000

  4 record(s) selected.
__________________
--
IBM Certified DBA on DB2 for Linux, UNIX, and Windows

DB2 v9.1.0.2 os 5.3.0.0
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