Portal | Manuals | References | Downloads | Info | Programs | JCLs | Master the Mainframes
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Usergroups Profile Log in to check your private messages Log in
 

 

Need DB2 Query by using SUBSTR

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> DB2
View previous topic :: :: View next topic  
Author Message
naveensrimf

New User


Joined: 04 Oct 2005
Posts: 31

PostPosted: Fri May 29, 2015 6:22 pm    Post subject: Need DB2 Query by using SUBSTR
Reply with quote

Hi,

Below table have account number and Information ID.

I need a query to display the Account number,Information ID where the last two digists are same in the Accounts number.


Table information given below


Table1:
------------
Account No Information ID
----------- ------------------
1000051 20001
1000061 20005
1000081 20009
2000051 20006
2000061 20007
3000051 20010
4000051 20011
6000051 20021
Back to top
View user's profile Send private message

Rohit Umarjikar

Senior Member


Joined: 21 Sep 2010
Posts: 1625
Location: NY,USA

PostPosted: Fri May 29, 2015 9:15 pm    Post subject:
Reply with quote

Insufficient info provided by you but try for this.

Code:
select Account_No, Information_ID 
from table
where 
substr(CAST( TRANSLATE('87654321',Account_No, '12345678')AS int ),1,1) =
substr(CAST( TRANSLATE('87654321',Account_No, '12345678')AS int ),2,1)
Back to top
View user's profile Send private message
Nic Clouston

Global Moderator


Joined: 10 May 2007
Posts: 1722
Location: UK

PostPosted: Sat May 30, 2015 2:16 am    Post subject:
Reply with quote

I think he means where the last 2 digits of an account number match the last two digits of another account number so from the data provided that is:
1000051
2000051
3000051
4000051 and
6000051
and
1000061 and
2000061

or is it that the last 2 digits of the info_id match the last 2 digits of the account number where nothing matches?

Clarification, and example output, is required.
Back to top
View user's profile Send private message
mohitsaini
Warnings : 1

New User


Joined: 15 May 2006
Posts: 90

PostPosted: Wed Jul 01, 2015 9:25 am    Post subject: Reply to: Need DB2 Query by using SUBSTR
Reply with quote

Nic - I think your former interpretation is correct. For that would the below query solve this problem?


Code:
SELECT A.Account_No, A.Information_ID  FROM TABLE A, TABLE B
WHERE SUBSTR(A.Account_No,(length(A.Account_No)-1),2) = SUBSTR(B.Account_No,(length(B.Account_No)-1),2);
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> DB2 All times are GMT + 6 Hours
Page 1 of 1

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
No new posts Join in SQL Query vickey_dw DB2 2 Tue Jan 17, 2017 12:15 am
This topic is locked: you cannot edit posts or make replies. MQ setup query mohitsaini Java & MQSeries 4 Sun Jan 08, 2017 1:53 am
No new posts DB2 query Using Recursion, Converting... smilewithashu2 DB2 1 Tue Jan 03, 2017 12:50 pm
No new posts SQL query to run through list of valu... Ni3-db2 DB2 14 Wed Dec 14, 2016 9:52 am
This topic is locked: you cannot edit posts or make replies. Db2 SQL query to convert rows into co... subratarec DB2 5 Thu Nov 17, 2016 4:51 pm


Facebook
Back to Top
 
Mainframe Wiki | Forum Rules | Bookmarks | Subscriptions | FAQ | Tutorials | Contact Us