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
 
SQL query - Help needed!

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

New User


Joined: 13 Nov 2006
Posts: 10

PostPosted: Sat Jan 23, 2010 2:11 am    Post subject: SQL query - Help needed!
Reply with quote

Hi,

I have a sql query where I have to use the following in the where clause:

A.EFFECTIVE_DATE = B.EFFECTIVE_DATE

A.EFFECTIVE_DATE has data type DATE while B. EFFECTIVE_DATE has data type DEC(8,0).

How can I use the above condition in my query.

Thanks
CB
Back to top
View user's profile Send private message

Akatsukami

Global Moderator


Joined: 03 Oct 2009
Posts: 1783
Location: Bloomington, IL

PostPosted: Sat Jan 23, 2010 2:26 am    Post subject:
Reply with quote

When the "effective date" is 1 July 1930, what will B.EFFECTIVE_DATE be?
Back to top
View user's profile Send private message
candyboy

New User


Joined: 13 Nov 2006
Posts: 10

PostPosted: Sat Jan 23, 2010 2:28 am    Post subject: Reply to: SQL query - Help needed!
Reply with quote

Sorry....here's the example:

A.EFFECTIVE_DATE = '2009-12-01'

B.EFFECTIVE_DATE = 20091201.
Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


Joined: 20 Oct 2006
Posts: 6970
Location: porcelain throne

PostPosted: Sat Jan 23, 2010 2:53 am    Post subject:
Reply with quote

candyboy,
you can cast from one datatype to another.
suggest you RTFM and perform some self-education with SPUFI.
Back to top
View user's profile Send private message
Akatsukami

Global Moderator


Joined: 03 Oct 2009
Posts: 1783
Location: Bloomington, IL

PostPosted: Sat Jan 23, 2010 2:56 am    Post subject:
Reply with quote

Well, that's a distinctly sub-optimal design icon_razz.gif

In any case, this ought to do it:
Code:

WHERE A.EFFECTIVE_DATE =
  DATE(SUBSTR(CHAR(B.EFFECTIVE_DATE),1,4) || '-' ||
       SUBSTR(CHAR(B.EFFECTIVE_DATE),5,2) || '-' ||
       SUBSTR(CHAR(B.EFFECTIVE_DATE),7,2))
Back to top
View user's profile Send private message
GuyC

Senior Member


Joined: 11 Aug 2009
Posts: 1281
Location: Belgium

PostPosted: Mon Jan 25, 2010 3:12 pm    Post subject:
Reply with quote

Akatsukami wrote:
Well, that's a distinctly sub-optimal design icon_razz.gif

In any case, this ought to do it:
Code:

WHERE A.EFFECTIVE_DATE =
  DATE(SUBSTR(CHAR(B.EFFECTIVE_DATE),1,4) || '-' ||
       SUBSTR(CHAR(B.EFFECTIVE_DATE),5,2) || '-' ||
       SUBSTR(CHAR(B.EFFECTIVE_DATE),7,2))

or
Code:
b.effective_date = year(a.effective-date) * 10000
                 + month(a.effective_date) * 100
                 + day(a.effective_date)

depending on which accesspath you want
Back to top
View user's profile Send private message
Mukesh Pandey

Active User


Joined: 11 Nov 2008
Posts: 143
Location: India

PostPosted: Mon Jan 25, 2010 3:49 pm    Post subject:
Reply with quote

Please try below condition in your where clause if it works.


where
SUBSTR(A.EFFECTIVE_DATE,1,4) = SUBSTR(B.EFFECTIVE_DATE,1,4)
AND
SUBSTR(A.EFFECTIVE_DATE,6,2) = SUBSTR(B.EFFECTIVE_DATE,5,2)
AND
SUBSTR(A.EFFECTIVE_DATE,9,2) = SUBSTR(B.EFFECTIVE_DATE,7,2)
Back to top
View user's profile Send private message
ashimer

Active Member


Joined: 13 Feb 2004
Posts: 551
Location: Bangalore

PostPosted: Mon Jan 25, 2010 4:06 pm    Post subject:
Reply with quote

You can convert A.effective_date to the other format by using

REPLACE(CHAR(A.EFFECTIVE_DATE,ISO),'-','')
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 query to fetch record which has only ... maxsubrat DB2 12 Mon Dec 11, 2017 5:03 pm
No new posts How to query MAXGENS of an existing P... Chuchulo Hatyzak JCL & VSAM 4 Wed Nov 22, 2017 10:23 pm
No new posts Native SQL Query kishpra DB2 1 Wed Nov 22, 2017 8:38 pm
No new posts Query on IEFBR14 with GDG Ashishpanpaliya JCL & VSAM 4 Tue Nov 07, 2017 8:34 pm
No new posts Query on XMITIP abdulrafi All Other Mainframe Topics 1 Wed Oct 25, 2017 6:54 pm

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