Add # of days and then pass it as a variable [message #624793] |
Thu, 25 September 2014 13:48 |
azeem87
Messages: 116 Registered: September 2005 Location: dallas
|
Senior Member |
|
|
Hi,
try to get max of a date column and then add 15 days and pass this calculated date as a where clause, tried with to_date, and to _char
getting invalid month error.
CREATE OR REPLACE PROCEDURE move_hist
IS
move_Dates varchar2(15);
BEGIN
select to_char(max(effectivedate),'DD-MON-YYYY' )+15 into move_Dates from txn_hist;
INSERT /*+ APPEND NOLOGGING*/
INTO txn_temp( txn_temp,
tnum_date,
TYPE)
SELECT tnum, effectiveDate, 'P'
FROM PRNT_TXN WHERE STATUS IN ('EX', 'DL')
AND (effectivedate) < move_Dates AND product = 'INTL';
COMMIT;
end;
Please suggest the option i should be using to get max then 15 days and pass it on where clause,
effectivedate in source table is of DATE datatype.
Thanks
|
|
|
|
|
Re: Add # of days and then pass it as a variable [message #624797 is a reply to message #624795] |
Thu, 25 September 2014 14:48 |
azeem87
Messages: 116 Registered: September 2005 Location: dallas
|
Senior Member |
|
|
thanks all for your time,
what i am trying to get is get the max(date)+15 and get this date in where clause.
based on that inner select you suggested i have this, please advice any suggestions on this.
CREATE OR REPLACE PROCEDURE move_hist
IS
move_Dates varchar2(15);
BEGIN
INSERT /*+ APPEND NOLOGGING*/
INTO txn_temp( txn_temp,
tnum_date,
TYPE)
SELECT tnum, effectiveDate, 'P'
FROM PRNT_TXN WHERE STATUS IN ('EX', 'DL')
AND (effectivedate) < (select max(effectivedate)+16 from txn_hist) AND product = 'INTL';
COMMIT;
INSERT /*+ APPEND NOLOGGING*/
INTO Qevents_hist
SELECT * FROM Qevents
WHERE (ENTEREDTIME) < (select max(ENTEREDTIME)+15 from Qevents_hist) ;
DELETE FROM QEVENTS
WHERE (ENTEREDTIME) < (select max(ENTEREDTIME)- 15 from Qevents_hist);
**** Here i have to use - ( minus ) because above insert will already insert the rows into Qevents_hist so ENTEREDTIME will be changed
commit;
end;
/
|
|
|
Re: Add # of days and then pass it as a variable [message #624798 is a reply to message #624795] |
Thu, 25 September 2014 14:50 |
Bill B
Messages: 1971 Registered: December 2004
|
Senior Member |
|
|
INSERT /*+ APPEND NOLOGGING*/
INTO txn_temp( txn_temp,
tnum_date,
TYPE)
SELECT tnum, effectiveDate, 'P'
FROM PRNT_TXN WHERE STATUS IN ('EX', 'DL')
AND (effectivedate) < select max(effectivedate)+15 from txn_hist)
AND product = 'INTL';
|
|
|
|