View previous topic :: View next topic |
Author |
Message |
THRIVIKRAM Beginner
Joined: 03 Oct 2005 Posts: 70 Topics: 34
|
Posted: Tue May 30, 2006 4:48 am Post subject: Hardcoding saturday date of every month |
|
|
Hello,
I have the following requirement.
I have a table X which will be updated by jobs that run daily.The rows updated on a particular day can be known from
LST_UPDT_DT colum of the X table.
Now, I have other monthly job which runs last saturday. This job retrieves all the rows that were updated since previous
run(last Saturday of previous month) to current month run(last saturday of this month).
The condition used is X.LST_UPDT_DT > '04/29/2006'.(for example)
But,every time we are hardcoding the Saturday date of previous month.
Is there any way by which we can overcome this burden. I mean,the condition must be such that
X.LST_UPDT_DT > [some quantity] , where [some quantity] should reflect the last saturday of previous month.
Thanks,
Thrivirkam. |
|
Back to top |
|
 |
kolusu Site Admin

Joined: 26 Nov 2002 Posts: 12378 Topics: 75 Location: San Jose
|
Posted: Tue May 30, 2006 5:26 am Post subject: |
|
|
THRIVIKRAM, Quote: |
But,every time we are hardcoding the Saturday date of previous month.
|
Here is a sql which will give you last saturday of the last month
Code: |
SELECT DATE(NEXT_DAY(LAST_DAY(CURRENT DATE - 1 MONTH) - 7 DAYS,'SAT'))
FROM SYSIBM.SYSDUMMY1;
|
Hope this helps...
Cheers
Kolusu _________________ Kolusu
www.linkedin.com/in/kolusu |
|
Back to top |
|
 |
THRIVIKRAM Beginner
Joined: 03 Oct 2005 Posts: 70 Topics: 34
|
Posted: Wed May 31, 2006 12:47 am Post subject: Hardcoding saturday date of every month |
|
|
Thanks Kolusu,
But Could you please tell how this code is working.
I need this because, when I try giving the date manually(just for testing in the QMF) instead of Current date its throwing the error
"Argument '2' of scalar function '-' is invalid."
Thnx for your time. |
|
Back to top |
|
 |
acevedo Beginner

Joined: 03 Dec 2002 Posts: 127 Topics: 0 Location: Europe
|
Posted: Wed May 31, 2006 1:23 am Post subject: |
|
|
then try
Code: |
SELECT CURRENT DATE
,DATE(NEXT_DAY(LAST_DAY([color=red]DATE[/color]('2006-05-31') - 1 MONTH) -7 DAYS,'SAT'))
FROM SYSIBM.SYSDUMMY1;
|
|
|
Back to top |
|
 |
shekar123 Advanced
Joined: 22 Jul 2005 Posts: 528 Topics: 90 Location: Bangalore India
|
Posted: Wed May 31, 2006 1:42 am Post subject: |
|
|
acevedo,
You have clearly given the query to know the current date as well the desired result
Code: |
SELECT CURRENT DATE,DATE(NEXT_DAY(LAST_DAY(DATE('2006-05-31') - 1 MONTH) - 7 DAYS,'SAT'))
FROM SYSIBM.SYSDUMMY1; |
OUTPUT
Code: |
COL1 COL2
---------- ----------
2006-05-31 2006-04-29
|
THRIVIKRAM,
You were getting error because you were trying to do '2006-05-31' - 1 MONTH , if you give DATE('2006-05-31') - 1 MONTH , then you will acheive the correct result because of compatibility. _________________ Shekar
Grow Technically |
|
Back to top |
|
 |
THRIVIKRAM Beginner
Joined: 03 Oct 2005 Posts: 70 Topics: 34
|
Posted: Wed May 31, 2006 2:29 am Post subject: Hardcoding saturday date of every month |
|
|
Yes,Its working!!!
Actually I overlooked that point.
Thanks. |
|
Back to top |
|
 |
|
|