This is my view_remit. I need to determine the months missing in the column month_paid
.
I used this code to get this table but I don't know how to determine the missing months.
SELECT RemitNo, PEN, Employer, month_paid, Total_PBR_Amt
FROM view_remit
JOIN (
SELECT 'JAN' as month_paid,'2016-01-01' as start,'2016-01-31' as end UNION ALL
SELECT 'FEB' as month_paid,'2016-02-01' as start,'2016-02-29' as end UNION ALL
SELECT 'MAR' as month_paid,'2016-03-01' as start,'2016-03-31' as end UNION ALL
SELECT 'APR' as month_paid,'2016-04-01' as start,'2016-04-30' as end UNION ALL
SELECT 'MAY' as month_paid,'2016-05-01' as start,'2016-05-31' as end UNION ALL
SELECT 'JUN' as month_paid,'2016-06-01' as start,'2016-06-30' as end UNION ALL
SELECT 'JUL' as month_paid,'2016-07-01' as start,'2016-07-31' as end UNION ALL
SELECT 'AUG' as month_paid,'2016-08-01' as start,'2016-08-31' as end UNION ALL
SELECT 'SEP' as month_paid,'2016-09-01' as start,'2016-09-30' as end UNION ALL
SELECT 'OCT' as month_paid,'2016-10-01' as start,'2016-10-31' as end UNION ALL
SELECT 'NOV' as month_paid,'2016-11-01' as start,'2016-11-30' as end UNION ALL
SELECT 'DEC' as month_paid,'2016-12-01' as start,'2016-12-31' as end
) M
ON view_remit.AP_From <= M.end
AND view_remit.AP_To >= M.start
ORDER BY PEN, AP_From
I need to get this output.
|PEN|Employer|month|
| 1 | a | MAR |
| 1 | a | JUN |
| 1 | a | JUL |
| 1 | a | SEP |
| 1 | a | OCT |
| 1 | a | NOV |
Any help is greatly appreciated. Thank you in advance.