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

SQL query - Help needed!


IBM Mainframe Forums -> DB2
Post new topic   Reply to topic
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
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: 1788
Location: Bloomington, IL

PostPosted: Sat Jan 23, 2010 2:26 am
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
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: 6966
Location: porcelain throne

PostPosted: Sat Jan 23, 2010 2:53 am
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: 1788
Location: Bloomington, IL

PostPosted: Sat Jan 23, 2010 2:56 am
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
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
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
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 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 Mainframe Programmer with CICS Skill... Mainframe Jobs 0
Search our Forums:

Back to Top