View previous topic :: View next topic
|
Author |
Message |
kedianirmal
New User
Joined: 08 Feb 2008 Posts: 82 Location: Bangalore, India
|
|
|
|
Hi,
My requirement is to read min(end_date) + 1 days in a cursor.
While fetching the data from the cursor the program is failing with -183.
Can somebody help if this is possible in cursor or what is the correct syntax.
Thanks,
Nirmal |
|
Back to top |
|
|
Craq Giegerich
Senior Member
Joined: 19 May 2007 Posts: 1512 Location: Virginia, USA
|
|
|
|
It would help if you show us the actual code you are using. |
|
Back to top |
|
|
GuyC
Senior Member
Joined: 11 Aug 2009 Posts: 1281 Location: Belgium
|
|
|
|
probably your min(end_date) = 9999-12-31
If you add 1 day you'll get -183
Possible solution is
case Min(end_date) < '9999-12-31'
then min(end_date) + 1 days
else '9999-12-31'
end |
|
Back to top |
|
|
kedianirmal
New User
Joined: 08 Feb 2008 Posts: 82 Location: Bangalore, India
|
|
|
|
The table has date in the format:
DD.MM.YYYY |
|
Back to top |
|
|
kedianirmal
New User
Joined: 08 Feb 2008 Posts: 82 Location: Bangalore, India
|
|
|
|
The cursor has select as below:
SELECT JS_PROD_CODE
,BR_CODE
,MIN(END_DATE + 1 DAYS )
FROM LNCVA098
I can fetch the minimum date and can add +1 day using intrinsic funtion but i am looking if cursor can directly give the desired output. |
|
Back to top |
|
|
GuyC
Senior Member
Joined: 11 Aug 2009 Posts: 1281 Location: Belgium
|
|
|
|
1) At least code min(end_date) + 1 days
it gives the same result as min(end_date + 1 days) but could be resolved using an index.
2) you'll need a group by
3) a table does not have dates in format DD.MM.YYYY
It can be that your db2 has external date representation dd.mm.yyyy.
just change 9999-12-31 to 31.12.9999 in my solution. |
|
Back to top |
|
|
GuyC
Senior Member
Joined: 11 Aug 2009 Posts: 1281 Location: Belgium
|
|
|
|
ps.
min(end_date + 1 days) will fail if any end_date = 31.12.9999
min(end_date) + 1 days will only fail when the min(end_date) = 31.12.9999 |
|
Back to top |
|
|
kedianirmal
New User
Joined: 08 Feb 2008 Posts: 82 Location: Bangalore, India
|
|
|
|
Thanks a lot,
The issue was of date 31.12.9999 only.
I added a where as AND END_DATE < '31.12.9999'
its working fine. Will test actual results tomorrow.
Thanks frineds. |
|
Back to top |
|
|
lkhiger
New User
Joined: 28 Oct 2005 Posts: 89
|
|
|
|
That's right. If the date = MAX date allowed in DB2 you can accept this SQLCODE.
Also you have not use "DAYS" but "DAY":
Code: |
min(end_date) + 1 day |
Because "DAYS" is the scalar function to find the difference between dates.
Lenny |
|
Back to top |
|
|
|