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
 

 

A query about a DB2 query.

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

Senior Member


Joined: 22 Apr 2006
Posts: 6258
Location: Mumbai, India

PostPosted: Fri Nov 07, 2008 11:16 am    Post subject: A query about a DB2 query.
Reply with quote

Hi,

Please have a look on the below query:
Code:
SELECT * FROM Table                                   
                                                               
WHERE SUBM_DT BETWEEN (CURRENT DATE-38  MONTHS) AND (CURRENT DATE-37 MONTHS);   
What if Table itself doesn't contain the data for 38th month ?
Back to top
View user's profile Send private message

Arun Raj

Moderator


Joined: 17 Oct 2006
Posts: 2276
Location: @my desk

PostPosted: Fri Nov 07, 2008 11:43 am    Post subject:
Reply with quote

Anuj,

I believe you'll not find any rows in the result set for the 38th month.

Let's take a simple example of current-date - 3 and current-date - 2.
Say Current-date is Nov-7. Hence the search window becomes Aug-7 to Sep-7. It's ok to have no rows in the table for Aug. If you dont have data in that window, you dont get that in your output. Correct me if I got this wrong.
Back to top
View user's profile Send private message
anandinmainframe

Active User


Joined: 31 May 2007
Posts: 171
Location: India

PostPosted: Fri Nov 07, 2008 12:02 pm    Post subject: Reply to: A query about a DB2 query.
Reply with quote

Hi,
Then the SQLCODE will be 100.
Back to top
View user's profile Send private message
dick scherrer

Site Director


Joined: 23 Nov 2006
Posts: 19270
Location: Inside the Matrix

PostPosted: Fri Nov 07, 2008 12:16 pm    Post subject:
Reply with quote

Hello,

Quote:
Then the SQLCODE will be 100.
The sqlcode=100 will only happen if there are no rows in the range. It will not occur if there are no rows in some part of the range.

Also, if this query is in a program, a "hit" on multiple rows would fail. If there might be multiple rows in the range, a cursor would be used.
Back to top
View user's profile Send private message
anandinmainframe

Active User


Joined: 31 May 2007
Posts: 171
Location: India

PostPosted: Fri Nov 07, 2008 12:37 pm    Post subject: Reply to: A query about a DB2 query.
Reply with quote

Hi Dick,
Quote:

What if Table itself doesn't contain the data for 38th month ?

thats the reason SQLCODE will be 100.
Back to top
View user's profile Send private message
dick scherrer

Site Director


Joined: 23 Nov 2006
Posts: 19270
Location: Inside the Matrix

PostPosted: Fri Nov 07, 2008 12:59 pm    Post subject:
Reply with quote

Hello,

Quote:
What if Table itself doesn't contain the data for 38th month ?
What determines if the 100 is raised is whether there are any rows that fall in the selection range. If there are no rows for month 38 but there are rows for some other month that fall within the range, there will be no sqlcode=100.

The 100 will only happen when there are no rows from any month(s) in the range.

There appears to bee far too much focus on month 38. Please re-read the example Arun posted. Maybe that will help clarify.
Back to top
View user's profile Send private message
Anuj Dhawan

Senior Member


Joined: 22 Apr 2006
Posts: 6258
Location: Mumbai, India

PostPosted: Sat Nov 08, 2008 3:02 am    Post subject:
Reply with quote

Hi,

No, SQL code 100 will not haapen - I'll not get any output if there is no data present for 38th month, this I know. But everyone here surrounding me was saying- we'll get the data...well.. icon_neutral.gif

We've a table which contains the data for 37 month, on every month end very first month's data is "purged" (Deleted) & most latest month data is added - due to a new request I need to preserve that very first month data some where backed-up on TAPE. To overcome this (said above), now, I've changed the logic to add the data to table first & then run the query in question to save the data. Hopefully 'am on right track.
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 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
No new posts Query on DB2 WLM stored procedures ashek15 DB2 8 Sun Feb 12, 2017 11:13 pm
No new posts GETMAIN/FREEMAIN query Suja.Sai CICS 9 Tue Jan 31, 2017 12:01 pm


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