MVSFORUMS.com Forum Index MVSFORUMS.com
A Community of and for MVS Professionals
 
 FAQFAQ   SearchSearch   Quick Manuals   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Partial INTEGER search

 
Post new topic   Reply to topic   printer-friendly view    MVSFORUMS.com Forum Index -> Database
View previous topic :: View next topic  
Author Message
drammo
Beginner


Joined: 13 Jan 2006
Posts: 20
Topics: 10

PostPosted: Thu May 04, 2006 2:07 pm    Post subject: Partial INTEGER search Reply with quote

The requirement is to identify all rows based on the last four digits of a column defined as integer.

Code:

Source Table

Account_ID
----------
       105
     34221
   2223123
   3310105
   4421105
  55210105

If the last four digits to match are 0105, the output should be

Account_ID
----------
       105
   3310105
  55210105


I am thinking in the lines of:

1. Convert the column to fixed length string (9 char long), padded with leading zeros
2. Substring and match the value.

I need help achiving the first or a completely different solution giving the desired result set.

Performance is critical (millions of rows in table), should run on DB2V7

Thanks!
Back to top
View user's profile Send private message
kolusu
Site Admin
Site Admin


Joined: 26 Nov 2002
Posts: 12378
Topics: 75
Location: San Jose

PostPosted: Thu May 04, 2006 2:22 pm    Post subject: Reply with quote

drammo,

Quite simple . You don't need char function or substring function. Simply divide the column by 10000 and check if the remainder is 0105

Code:

SELECT * 
  FROM TABLE
 WHERE MOD(ACCOUNT_ID,10000) = 0105


Hope this helps...

Cheers

Kolusu
_________________
Kolusu
www.linkedin.com/in/kolusu
Back to top
View user's profile Send private message Send e-mail Visit poster's website
drammo
Beginner


Joined: 13 Jan 2006
Posts: 20
Topics: 10

PostPosted: Thu May 04, 2006 2:31 pm    Post subject: Reply with quote

I am a dumbo. Thanks Kolusu.
Back to top
View user's profile Send private message
drammo
Beginner


Joined: 13 Jan 2006
Posts: 20
Topics: 10

PostPosted: Thu May 04, 2006 2:34 pm    Post subject: Reply with quote

Out of curosity, is there a way to pad leading zeros to an integer column, while converting it to Char?

Thanks!
Back to top
View user's profile Send private message
kolusu
Site Admin
Site Admin


Joined: 26 Nov 2002
Posts: 12378
Topics: 75
Location: San Jose

PostPosted: Thu May 04, 2006 2:37 pm    Post subject: Reply with quote

drammo,

Use the Scalar function DIGITS to pad leading zeroes.
Code:

SELECT DIGITS(ACCOUNT_ID)
  FROM TABLE
;


Check this link which explains in detail about DIGITS function

http://publibz.boulder.ibm.com/cgi-bin/bookmgr_OS390/BOOKS/DSNSQH11/3.2.27?SHELF=&DT=20010718164132&CASE=

Hope this helps...

Cheers

Kolusu
_________________
Kolusu
www.linkedin.com/in/kolusu
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic   printer-friendly view    MVSFORUMS.com Forum Index -> Database All times are GMT - 5 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


MVSFORUMS
Powered by phpBB © 2001, 2005 phpBB Group