× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.



Hi everyone
We are on V7r3
I have a number of SQL queries that are run early each Monday, that collects data from the previous Monday through yesterday (Sunday), using the following code

WHERE nbtygpl.idate((a.CHKDAT), '*MDY')
between (current_date - 7 day) and
(current_date - 1 day) and
Followed by Other selection criteria

I was asked today (Wednesday September 1, 2021) if I could run these but extract the data from this past Monday (August 30, 2021)
So - for today - I changed the selection criteria to be
WHERE nbtygpl.idate((a.CHKDAT), '*MDY')
between (current_date - 2 day) and
(current_date - 1 day) and
Followed by the remaining selection criteria

It looks like this "special" run will be needed for each month end

NOW - here is my question
In SQL, s there any way to determine how long ago the prior Monday was?
So that if the job is run on a Monday - the field Prior_Mondays_days_ago (in the SQL below) is 7

between (current_date - Prior_Mondays_days_ago day) and

If the job is run on Tuesday - Prior_Mondays_days_ago (in the SQL) is 1
Wednesday - Prior_Mondays_days_ago (in the SQL) is 2
Thursday - Prior_Mondays_days_ago (in the SQL) is 3
Friday - Prior_Mondays_days_ago (in the SQL) is 4
Saturday - Prior_Mondays_days_ago (in the SQL) is 5
Sunday - Prior_Mondays_days_ago (in the SQL) is 6
Monday - Prior_Mondays_days_ago (in the SQL) is 7
As always - all answers gratefully accepted



Alan Shore
Solutions Architect
IT Supply Chain Execution

[cid:image001.png@01D79F0C.A45ED020]

60 Orville Drive
Bohemia, NY 11716
Phone [O] : (631) 200-5019
Phone [C] : (631) 880-8640
E-mail : ASHORE@xxxxxxxxxxxxxxxxxxxx

'If you're going through hell, keep going.'
Winston Churchill


As an Amazon Associate we earn from qualifying purchases.

This thread ...

Follow-Ups:

Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.