0
CREATE OR REPLACE PROCEDURE PRC_TWO_DAY_EXTEND 
AS 
BEGIN
    UPDATE CHECKOUT
    SET CHECK_IN_DATE = CHECK_IN_DATE + 2 
    JOIN PATRON ON PATRON.PAT_ID = CHECKOUT.PAT_ID
    FROM CHECKOUT  
    WHERE PATRON.PAT_TYPE = 'STUDENT';
END;

EXEC PRC_TWO_DAY_EXTEND;

Basically I need to just add two days to the check in date but I cant figure out how to join them and then update them, because its based on whether or not PAT_TYPE = 'STUDENT'

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Alex Walker
  • 51
  • 1
  • 5

2 Answers2

1

Your date arithmetics suggests Oracle, so let me assume that's the database you are running.

In that database, you could phrase the query as:

update checkout c
set check_in_date = check_in_date + 2
where exists (
    select 1
    from patron p
    where p.pat_id = c.pat_id and p.pat_type = 'STUDENT'
)

This updates the check-in date of rows whose pat_id can be found in patron with a pat_type having value 'STUDENT'.

GMB
  • 216,147
  • 25
  • 84
  • 135
1

Yet another option is to use the MERGE as follows:

Merge into checkout c
Using
(select pat_id 
   From patron
  Where pat_type = 'STUDENT') p
On (p.pat_id = c.pat_id)
When matched then
Update set c.check_in_date = c.check_in_date + 2
Popeye
  • 35,427
  • 4
  • 10
  • 31