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

A query about a DB2 query.


IBM Mainframe Forums -> DB2
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
Anuj Dhawan

Superior Member


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

PostPosted: Fri Nov 07, 2008 11:16 am
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: 2481
Location: @my desk

PostPosted: Fri Nov 07, 2008 11:43 am
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
Reply with quote

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

Moderator Emeritus


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

PostPosted: Fri Nov 07, 2008 12:16 pm
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
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

Moderator Emeritus


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

PostPosted: Fri Nov 07, 2008 12:59 pm
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

Superior Member


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

PostPosted: Sat Nov 08, 2008 3:02 am
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 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 Issue with EXEC CICS QUERY SECURITY c... CICS 6
Search our Forums:

Back to Top