How to insert an entry from table A into table B based on the conditions in table C.
Table a:
ID Name DateFrom DateTo 1 Alex 22-7-2015 26-7-2015 2 Alice 21-8-2015 25-8-2015
Table C:
ID Quarter DateFrom DateTo 1 Quater 1 1-7-2015 31-7-2015 2 Quater 2 1-8-2015 31-8-2015
If the entries from table A are between the date range in table C. It will be inserted into the new table B.
Foreclosure - Table B
insert into redemption(staffID,staffName,department,pointsAccumulated,referrerID) select referrerStaffID,referrerName,referrerDepartment,SUM(points),activeDirectoryID FROM referral WHERE NOT EXISTS (select * from redemption1 where referrerID=activeDirectoryID) group by activeDirectoryID;
source share