Portal | Manuals | References | Downloads | Info | Programs | JCLs | Master the Mainframes
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Usergroups 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: 1770
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: 6968
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: 1770
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 Need DB2 query to fetch previous row ! Chandan1993 DB2 10 Sat Jun 03, 2017 10:43 am
This topic is locked: you cannot edit posts or make replies. SORT trick needed bshkris SYNCSORT 6 Tue May 02, 2017 4:35 am
No new posts JCL to Set Return code based on DB2 S... vinu78 DB2 17 Mon Mar 13, 2017 9:47 pm
No new posts SQL query not working in Cobol program. CuriousMainframer COBOL Programming 14 Wed Feb 22, 2017 5:56 pm
No new posts Omegamon for DB2 query ashek15 DB2 0 Wed Feb 15, 2017 11:25 am


Facebook
Back to Top
 
Mainframe Wiki | Forum Rules | Bookmarks | Subscriptions | FAQ | Tutorials | Contact Us