I'm trying to INNER JOIN
two tables: tbl_profile
and tbl_employment
tbl_profile
has:
id_no (pk)
lastName (String)
firstName (String)
tbl_employment
has:
company_no (pk)
id_no (fk)
datehired (date)
company (string)
end_employment (date)
Each person in the profile
table can have many employments or none at all in life. But I need to find the latest date_hired
of that person.
These are the conditions I want to set:
- if the date_hired of the person is not empty and the end_employment is empty, it means that the person is CURRENTLY EMPLOYED
- if the date_hired of the person is not empty and the end_employment is also not empty, it means that the person is CURRENTLY UNEMPLOYED
- if the date_hired of the person is empty, then it means that the person is UNEMPLOYED.
After determining the conditions above, my query will add another column named STATUS
which will only state EMPLOYED
or UNEMPLOYED
based on the conditions above.
However, when I convert this logic into a query, it states
Syntax Error: Operator is missing.
I read a book about using when
-then
statement like if
-else
does in SELECT
of a query is possible. But with my query, it doesn't work. What is wrong with this?
SELECT p.id_no, p.lastName ,
(CASE
WHEN c.date_hired != "" AND c.end_employment = "" THEN 'employed'
WHEN c.date_hired != "" AND c.end_employment != "" THEN 'unemployed'
WHEN c.date_hired = "" THEN 'unemployed'
END)
AS employment_status
FROM tbl_profile AS p INNER JOIN tbl_employment AS c ON p.id_no= c.id_no;
It says that the error is within this part:
(CASE
WHEN c.date_hired != "" AND c.end_employment = "" THEN 'employed'
WHEN c.date_hired != "" AND c.end_employment != "" THEN 'unemployed'
WHEN c.date_hired = "" THEN 'unemployed' END)
P.S: I did the query in Microsoft Access