Query is not producing the correct results(SOLVED)
-
Hello experts, I hope this question falls under the Database category. I have this query:
Select e.Dept, e.division, a.managerID,e.EmpName,e.empnum, e.Email,e.zip, e.SSN FROM Emp e, Angular a Where e.empID = a.managerid OR e.empID = @empid and password=@pass
What I am attempting to do is that if a user attempts to log in and that user is a manager, redirect him/her to manager screen. Otherwise, redirect to employee screen. The issue is that when I run that query, I expect to see records associated with that manager. It shows ALL employees belonging to different managers. How do I tweak this to work? A bit more info: There are two tables, Emp table with following relevant attributes: EmpName, EmpID Dept Division Password SSN User logs in with EmpID as username and last digits of SSN as password Then this other table called Angular with following relevant attributes: EmpID - FK to EmpID from Emp table ManagerID FK to EmpID from Emp table Status (done or pending) The logic we are trying to employ is that if empID (from Emp table) that the user is logging in with matches ManagerID (from Angular table) then this must be a manager, redirect him or her to manger page. If empID from Emp table does not match managerID from Angular table, redirect to employee table. What am I doing wrong? The code for redirect is asp.net and no need to post it here because if the query is correct, that will work. Your assistance is greatly appreciated.
-
Hello experts, I hope this question falls under the Database category. I have this query:
Select e.Dept, e.division, a.managerID,e.EmpName,e.empnum, e.Email,e.zip, e.SSN FROM Emp e, Angular a Where e.empID = a.managerid OR e.empID = @empid and password=@pass
What I am attempting to do is that if a user attempts to log in and that user is a manager, redirect him/her to manager screen. Otherwise, redirect to employee screen. The issue is that when I run that query, I expect to see records associated with that manager. It shows ALL employees belonging to different managers. How do I tweak this to work? A bit more info: There are two tables, Emp table with following relevant attributes: EmpName, EmpID Dept Division Password SSN User logs in with EmpID as username and last digits of SSN as password Then this other table called Angular with following relevant attributes: EmpID - FK to EmpID from Emp table ManagerID FK to EmpID from Emp table Status (done or pending) The logic we are trying to employ is that if empID (from Emp table) that the user is logging in with matches ManagerID (from Angular table) then this must be a manager, redirect him or her to manger page. If empID from Emp table does not match managerID from Angular table, redirect to employee table. What am I doing wrong? The code for redirect is asp.net and no need to post it here because if the query is correct, that will work. Your assistance is greatly appreciated.
Something like this?
SELECT
e.Dept,
e.division,
a.managerID,
e.EmpName,
e.empnum,
e.Email,
e.zip,
e.SSN
FROM
Emp As e
LEFT JOIN Angular As a
ON a.managerid = e.empID
WHERE
e.empID = @empid
And
e.password = @pass
"These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer
-
Something like this?
SELECT
e.Dept,
e.division,
a.managerID,
e.EmpName,
e.empnum,
e.Email,
e.zip,
e.SSN
FROM
Emp As e
LEFT JOIN Angular As a
ON a.managerid = e.empID
WHERE
e.empID = @empid
And
e.password = @pass
"These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer