I am struggling with a logical puzzle while working with joins. So I have 2 tables shown below EmpStatus and EmpEIN. So what I want to do is join these 2 tables and produce the output like below. If a consumer had an EmpNumber for a complete month than the should get a status in a different row, else the statuses should go with a null entry in the EmpNumber.
I am not sure how I can join these 2 tables to produce the output. If some sql pro can help me out that will be awesome.
EmpStatus:
ConsumerID JanStatus FebStatus MarStatus AprStatus MayStatus
1001 P P P P P
1002 P P P P P
1003 P P P P P
1004 P P P P P
1005 P P P P P
EmpEIN:
ConsumerID EmpNumber EmpNumberStartDate EmpNumberEndDate
1001 102020202 1/1/2015 31/1/2015 -- dates in dd/mm/yyyy format
1001 210201021 1/2/2015 31/3/2015
1002 NULL NULL NULL
1003 NULL NULL NULL
1004 NULL NULL NULL
1005 NULL NULL NULL
OUTPUT:
ConsumerID EmpNumber JanStaus FebStatus MarStatus AprStatus MayStatus
1001 102020202 P NULL NULL NULL NULL
1001 210201021 NULL P P NULL NULL
1001 NULL NULL NULL NULL P P
1002 NULL P P P P P
1003 NULL P P P P P
1004 NULL P P P P P
1005 NULL P P P P P