Loop Query of Data

  • Hi,

    I am having trouble getting my head around a problem. I am trying to retrieve info from a single table.

    To explain and simplify the the problem the table would hold basic user info with the following columns.

    user ID, 1st username, managersID.

    I would like to pull info out that lists a users id, name, mangers id and the mangers name.

    The managers name comes from putting the managers ID into the user id column and then selecting the name.

    I was thinking about embedded select statements or using a cursor but not sure if this would work.

    Any help would be appreciated.

  • Here it is....

    SELECTU.UserID, U.UserName, U.ManagerID, M.UserName AS ManagerName

    FROMdbo.Users E

    LEFT JOIN dbo.Users M ON E.ManagerID = M.UserID

    --Ramesh


  • Thanks Ramesh,

    As you can see in the orginal message I was looking in the wrong direction.

    I have been able to apply in theory multiple joins to get the data I was after.

  • SO... what does all of that mean? Did you use Ramesh's solution or not? If not, would you post your solution, please?

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.

    Change is inevitable... Change for the better is not.


    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)

  • Yes. I could get the data I was after by using a join

Viewing 5 posts - 1 through 5 (of 5 total)

You must be logged in to reply to this topic. Login to reply