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: 1746
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: 6966
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: 1746
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: 1278
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 Join in SQL Query vickey_dw DB2 2 Tue Jan 17, 2017 12:15 am
This topic is locked: you cannot edit posts or make replies. MQ setup query mohitsaini Java & MQSeries 4 Sun Jan 08, 2017 1:53 am
No new posts DB2 query Using Recursion, Converting... smilewithashu2 DB2 1 Tue Jan 03, 2017 12:50 pm
No new posts SQL query to run through list of valu... Ni3-db2 DB2 14 Wed Dec 14, 2016 9:52 am
This topic is locked: you cannot edit posts or make replies. Db2 SQL query to convert rows into co... subratarec DB2 5 Thu Nov 17, 2016 4:51 pm


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