Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Database & SysAdmin
  3. Database
  4. Query is not producing the correct results(SOLVED)

Query is not producing the correct results(SOLVED)

Scheduled Pinned Locked Moved Database
questiondatabasecsharpjavascriptasp-net
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    samflex
    wrote on last edited by
    #1

    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.

    Richard DeemingR 1 Reply Last reply
    0
    • S samflex

      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.

      Richard DeemingR Offline
      Richard DeemingR Offline
      Richard Deeming
      wrote on last edited by
      #2

      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

      "These people looked deep within my soul and assigned me a number based on the order in which I joined" - Homer

      S 1 Reply Last reply
      0
      • Richard DeemingR Richard Deeming

        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

        S Offline
        S Offline
        samflex
        wrote on last edited by
        #3

        Ahhh! Brilliant again Richard. Thanks as always. Very much appreciated.

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups