IBM Mainframe Forum Index
 
Log In
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Register
 

How to compare 1st 5 fields from 2 tables


IBM Mainframe Forums -> DB2
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
maxsubrat

Active User


Joined: 27 Feb 2008
Posts: 110
Location: india

PostPosted: Fri Feb 15, 2013 5:10 pm
Reply with quote

Can someone correct me if i use to compare the 1st 5 fields between 2 tables... will the below condition work? when i run the below condition, then i am getting records which are equal to rather than not equal to.

SELECT * FROM TABLE 1 C
, TABLE 2 G
WHERE EMP1 = EMP2
AND ((C.ORIGIN,1,5) <> (G.ORIGIN,1,5)
OR (C.DEST,1,5) <> (G.DEST, 1,5) ) ;

Thanks in advance
Max
Back to top
View user's profile Send private message
Jerin Scaria

New User


Joined: 17 Feb 2013
Posts: 1
Location: USA

PostPosted: Sun Feb 17, 2013 3:01 am
Reply with quote

use SUBSTR function to get the first few chars of the column value.

and if you you are using two not equal to conditions, i think it should be connected with logical operator AND rather than OR.

SELECT * FROM TABLE 1 C
, TABLE 2 G
WHERE EMP1 = EMP2
AND (SUBSTR(C.ORIGIN,1,5) <> SUBSTR(G.ORIGIN,1,5)
AND SUBSTR(C.DEST,1,5) <> SUBSTR(G.DEST, 1,5) ) ;
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic View Bookmarks
All times are GMT + 6 Hours
Forum Index -> DB2

 


Similar Topics
Topic Forum Replies
No new posts Compare 2 files and retrive records f... DFSORT/ICETOOL 2
No new posts Compare 2 files(F1 & F2) and writ... JCL & VSAM 8
No new posts Compare only first records of the fil... SYNCSORT 7
No new posts Compare two files with a key and writ... SYNCSORT 3
No new posts Compare latest 2 rows of a table usin... DB2 1
Search our Forums:

Back to Top