What i'm trying to do is 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.
This is 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 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 doesnt. What must be wrong with this?
SELECT p.alumni_no, p.lname,
(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_company AS c ON p.id_no= c.id_no;
P.S: I did the query in MS Access
Aucun commentaire:
Enregistrer un commentaire