View previous topic :: View next topic
|
Author |
Message |
Anuj Dhawan
Superior Member
Joined: 22 Apr 2006 Posts: 6250 Location: Mumbai, India
|
|
|
|
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 |
|
|
Arun Raj
Moderator
Joined: 17 Oct 2006 Posts: 2481 Location: @my desk
|
|
|
|
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 |
|
|
anandinmainframe
Active User
Joined: 31 May 2007 Posts: 171 Location: India
|
|
|
|
Hi,
Then the SQLCODE will be 100. |
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19244 Location: Inside the Matrix
|
|
|
|
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 |
|
|
anandinmainframe
Active User
Joined: 31 May 2007 Posts: 171 Location: India
|
|
|
|
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 |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19244 Location: Inside the Matrix
|
|
|
|
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 |
|
|
Anuj Dhawan
Superior Member
Joined: 22 Apr 2006 Posts: 6250 Location: Mumbai, India
|
|
|
|
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..
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 |
|
|
|