Search code examples
sql-serversql-server-2005t-sql

Iterate over a rowset, get a field which matches parameter, and then another field from that row


I have a stored procedure which has to get a password from my Users table.

I am using a Username as a parameter. What is the best way to get the row where the Username field's contents match the Username parameter, and then the password (as this is the Username/password pair for one user).

Cursors are one way to iterate over a rowset but these aren't desirable.

I am on Sql Server 2005.


Solution

  • It sounds like you just need a standard SELECT query:

    SELECT username_column, password_column
    FROM your_table
    WHERE username_column = @usernameparam
    

    (Or am I misunderstanding the question?)