Results Set based on Dynamic Date stored in variable [message #644758] |
Mon, 16 November 2015 15:50 |
|
Anil98765
Messages: 3 Registered: November 2015 Location: Earth
|
Junior Member |
|
|
Hi, I'm very new to the Oracle world coming from a SQL background. I could do this in SQL Server.
Basically, I created 2 variable for Start/End date to pull the previous Monday thru Sunday. (Example if today is 11/16 - I'd pull 11/9 - 11/15). I was to dynamically get those dates and assign it to the PrevWeekStateDate & PrevWeekEndDate to use them in the where condition.
--Declare Variables
variable PrevWeekStateDate varchar2(30);
variable PrevWeekEndDate varchar2(30);
--Hardcodes date - I dont want this dynamically get the dates
exec :PrevWeekStateDate :='11022015';
exec :PrevWeekEndDate :='11082015';
/* How do I assign the select to the var?
--Set Variables bases on current date to get previous Monday and previous Sunday
exec :PrevWeekStateDate := (select next_day (sysdate-8,'MONDAY') from dual);
exec :PrevWeekEndDate := (select next_day (sysdate-7, 'SUNDAY') from dual);
--2nd attempt to assign via into
--Set Variables bases on current date to get previous Monday and previous Sunday
select next_day (sysdate-8,'MONDAY') into PrevWeekStateDate from dual;
select next_day (sysdate-7, 'SUNDAY') into PrevWeekEndDate from dual;
*/
--Get results set
SELECT
COUNT(*)
FROM worklight.TBL_ACTIVITY_LOG
WHERE ACTIVITY LIKE '%Refill Proc%'
AND activity_dttm between to_date(:PrevWeekStateDate, 'mmddyyyy')
AND to_date(:PrevWeekEndDate, 'mmddyyyy');
Any insight would be great as I started a new job and trying to impress the boss by getting this scheduled.
|
|
|
|
|
|
|
|
|