BlackOps
November 25th, 2007, 08:40 AM
Hello i have created database of Employees and their rights to access many areas, using MS Access(see the attached image of my database schema)
now, lets say i want to select ALL EmployeeIDs from r_rights table, who have access to areas 1 OR 5,
here is my SQL code:
SELECT r_rights.EmployeeID, r_rights.AreaID
FROM r_rights
WHERE r_rights.AreaID = 1 OR r_rights.AreaID = 5;
it returns all EmployeeIDs who has access to area1 or area5
But what if i want to list ONLY EmployeeIDs who have access to area1 AND area5?
i tried to put this line in the above code:
WHERE r_rights.AreaID = 1 AND r_rights.AreaID = 5;
but it didnt work...no errors, but it didnt give any results
similiar problem comes out when i want to select, for example all employees whoose card expires on 5th month of 2008 year... here is the SQL for it:
SELECT e_employees.FirstName, e_employees.LastName, e_employees.FathersName, d_divisions.DivisionName, t_titles.TitleName, e_employees.CardExpireDate
FROM t_titles INNER JOIN (d_divisions INNER JOIN e_employees ON d_divisions.DivisionID = e_employees.DivisionID) ON t_titles.TitleID = e_employees.TitleID
WHERE (Year(CardExpireDate)) = 2008 AND (Month(CardExpireDate)) = 5;
no errors, but it doesnt show any record...
please help me to solve these problems, thank you
now, lets say i want to select ALL EmployeeIDs from r_rights table, who have access to areas 1 OR 5,
here is my SQL code:
SELECT r_rights.EmployeeID, r_rights.AreaID
FROM r_rights
WHERE r_rights.AreaID = 1 OR r_rights.AreaID = 5;
it returns all EmployeeIDs who has access to area1 or area5
But what if i want to list ONLY EmployeeIDs who have access to area1 AND area5?
i tried to put this line in the above code:
WHERE r_rights.AreaID = 1 AND r_rights.AreaID = 5;
but it didnt work...no errors, but it didnt give any results
similiar problem comes out when i want to select, for example all employees whoose card expires on 5th month of 2008 year... here is the SQL for it:
SELECT e_employees.FirstName, e_employees.LastName, e_employees.FathersName, d_divisions.DivisionName, t_titles.TitleName, e_employees.CardExpireDate
FROM t_titles INNER JOIN (d_divisions INNER JOIN e_employees ON d_divisions.DivisionID = e_employees.DivisionID) ON t_titles.TitleID = e_employees.TitleID
WHERE (Year(CardExpireDate)) = 2008 AND (Month(CardExpireDate)) = 5;
no errors, but it doesnt show any record...
please help me to solve these problems, thank you