How to insert record from Table A to 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 records from Table A is between the date range in Table C. It will insert into a new Table B.
Redemption is 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;
 
     
     
     
     
    