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

Comparison of dates in DB2 for a join query.


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

New User


Joined: 21 Jan 2010
Posts: 6
Location: Pune

PostPosted: Tue Feb 16, 2010 12:54 pm
Reply with quote

I need to write a join query on two tables where in I need to join the tables on two dates, however the format of the dates is different. In one table the format of the date is in DATE format e.g 2008-05-06 and the other table has date in format as '06MAY2008' (CHARACHTER (9)).How do I do the comparison? Thanks in Advance.
Back to top
View user's profile Send private message
ashimer

Active Member


Joined: 13 Feb 2004
Posts: 551
Location: Bangalore

PostPosted: Tue Feb 16, 2010 2:44 pm
Reply with quote

You better go with a subquery rather than a join. This join will never be effective due to different data formats.
Back to top
View user's profile Send private message
Shobs

New User


Joined: 21 Jan 2010
Posts: 6
Location: Pune

PostPosted: Tue Feb 16, 2010 2:47 pm
Reply with quote

Can you please help me with the sub-query as I am new to DB2? Thanks.
Back to top
View user's profile Send private message
ashimer

Active Member


Joined: 13 Feb 2004
Posts: 551
Location: Bangalore

PostPosted: Tue Feb 16, 2010 3:05 pm
Reply with quote

Code:

SELECT * FROM TABLE A WHERE DATE_COL IN
(SELECT SUBSTR('06MAY2008',6,4)||'-'||
CASE SUBSTR('06MAY2008',3,3)
WHEN 'JAN' THEN '01'
WHEN 'FEB' THEN '02'
-----
-----
WHEN 'MAY' THEN '05'
-----
------
END
||'-'||SUBSTR('06MAY2008',1,2)
FROM TABLE B
)

Change '06MAY2008' with your date column in table B.
IMO the DB design could have been done in a better way.
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 RC query -Time column CA Products 3
No new posts Dynamically pass table name to a sele... DB2 2
No new posts Query on edit primary command CLIST & REXX 5
No new posts Query on edit primary command CLIST & REXX 1
No new posts Join multiple records using splice DFSORT/ICETOOL 5
Search our Forums:

Back to Top