Portal | Manuals | References | Downloads | Info | Programs | JCLs | Mainframe wiki | Quick Ref
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Profile Log in to check your private messages Log in
 
Comparison of dates in DB2 for a join query.

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> DB2
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    Post subject: Comparison of dates in DB2 for a join query.
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    Post subject:
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    Post subject: Reply to: Comparison of dates in DB2 for a join query.
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    Post subject:
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    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 HEX value search in a DB2 query maxsubrat DB2 2 Wed Oct 04, 2017 3:04 pm
No new posts Create procedure issues -628 when add... chandraBE DB2 1 Mon Sep 18, 2017 12:16 pm
No new posts Join records from 2 files with No Dup... Poha Eater DFSORT/ICETOOL 22 Sun Aug 27, 2017 10:35 pm
No new posts Can we limit length in concatenation ... balaji81_k DB2 7 Tue Aug 22, 2017 2:50 am
No new posts Reduce CPU Times for Join Sort santoshn SYNCSORT 12 Sat Jun 10, 2017 1:40 pm

Facebook
Back to Top
 
Job Vacancies | Forum Rules | Bookmarks | Subscriptions | FAQ | Polls | Contact Us