query in sql server for retrieving rows

Posted by Arash khangaldi on Stack Overflow See other posts from Stack Overflow or by Arash khangaldi
Published on 2012-09-19T17:32:45Z Indexed on 2012/09/20 15:38 UTC
Read the original article Hit count: 255

I have a table that contains the following 4 columns:

  • id
  • name
  • lastname
  • phone

I want to write a stored procedure that gets an id as parameter, and then gets the name of that id and then use that name to get all the rows that their name is equal to the names that i found in last step! here it is my query, i know it's wrong but i'm new to sql commands:

ALTER PROCEDURE dbo.GetAllNames
@id int
AS
    select name as Name from Users where id = @id
    -- i don't how to retrieve the names that are equal to Name
select * from Users where name = Name 

can you correct my query and help me? Thanks.

© Stack Overflow or respective owner

Related posts about sql

Related posts about sql-server-2008