View previous topic :: View next topic |
Author |
Message |
drammo Beginner
Joined: 13 Jan 2006 Posts: 20 Topics: 10
|
Posted: Thu May 04, 2006 2:07 pm Post subject: Partial INTEGER search |
|
|
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 |
|
 |
kolusu Site Admin

Joined: 26 Nov 2002 Posts: 12378 Topics: 75 Location: San Jose
|
Posted: Thu May 04, 2006 2:22 pm Post subject: |
|
|
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 |
|
 |
drammo Beginner
Joined: 13 Jan 2006 Posts: 20 Topics: 10
|
Posted: Thu May 04, 2006 2:31 pm Post subject: |
|
|
I am a dumbo. Thanks Kolusu. |
|
Back to top |
|
 |
drammo Beginner
Joined: 13 Jan 2006 Posts: 20 Topics: 10
|
Posted: Thu May 04, 2006 2:34 pm Post subject: |
|
|
Out of curosity, is there a way to pad leading zeros to an integer column, while converting it to Char?
Thanks! |
|
Back to top |
|
 |
kolusu Site Admin

Joined: 26 Nov 2002 Posts: 12378 Topics: 75 Location: San Jose
|
|
Back to top |
|
 |
|
|