I have written a procedure that should increase salary for employee table according to days of each persons experience. The values for increase are in another table. Could someone tell me why it doesn't increase salary for employees working more than 3650 days?
DECLARE
row record;
row2 record;
dateDiff int;
BEGIN
FOR row IN EXECUTE 'SELECT * FROM employee'
LOOP
FOR row2 IN SELECT * FROM increases
LOOP
dateDiff := now()::date - row.empjoindate;
IF dateDiff> 3650 THEN
RAISE NOTICE '%', dateDiff;
END IF;
IF dateDiff >= row2.employment_length_from
AND dateDiff < row2.employment_length_to THEN
UPDATE employee SET empsalary = empsalary + row2.pay_rise WHERE empid = row.empid;
END IF;
END LOOP;
END LOOP;
END;
Table for increasing salaries looks like this:
id | employment_length_from | employment_length_to | pay_rise
----+------------------------+----------------------+----------
2 | 3650 | 7300 | 200
3 | 7300 | 10950 | 400
4 | 10950 | 14600 | 600
5 | 14600 | 18250 | 800
6 | 18250 | 21900 | 1000
1 | 0 | 3650 | 100
If something is not clear just ask me questions.
Edit
The table definitions are: For Employee:
Column | Type | Modifiers
-----------------+-----------------------------+-----------
empid | integer | not null
empemailaddress | character varying(255) | not null
empjoindate | date |
emplastname | character varying(255) |
emplogintime | timestamp without time zone |
empname | character varying(255) |
ispermanent | boolean | not null
empsalary | double precision |
Indexes:
"employee_pkey" PRIMARY KEY, btree (empid)
For increases:
Column | Type | Modifiers
------------------------+------------------+-----------
id | integer | not null
employment_length_from | integer |
employment_length_to | integer |
pay_rise | double precision |
Indexes:
"increases_pkey" PRIMARY KEY, btree (id)