Click here to Skip to main content
15,901,001 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi,
I have a city table and a member table.The city table contains CityID and Name.Member table contain MemberId,CityId,Name.I want to retrive the city name depending on the CityId present in MemberTable by joining the two table.Can any body please tell me how to do this by stored procedure ??

Thank you..
Posted
Comments
Thanks7872 10-Dec-14 5:41am    
What have you tried till now?
Monicavensaslas 10-Dec-14 5:42am    
Y you need stored procedure?? Can you share your code using implrove question link...that will help us to understand what exactly you are asking...

hi
create procedure procedureName(
@cityId int
)
As
your Query like this
SQL
BEGIN
 SELECT MemberId, Name as MemberName, City.Name as CityName
 FROM Member INNER JOIN CITY ON Member.CityId = City.CityId where CityId=@cityId 
END




--execute procedure
--pass cityId
--exec procedureName 1
 
Share this answer
 
v2
SQL
Hi !!

Please find the Stored Procedure Below which does the task you desired.

CREATE PROCEDURE usp_GetMembers
AS
BEGIN
 SELECT MemberId, Name as MemberName, City.Name as CityName
 FROM Member INNER JOIN CITY ON(Member.CityId = City.CityId)
END


Also visit the following links to understand the Create Procedure syntax and SQL Joins

http://msdn.microsoft.com/en-us/library/ms187926.aspx[^]

http://www.w3schools.com/sql/sql_join.asp[^]
 
Share this answer
 
try..
SQL
CREATE PROCEDURE uspGetAddress
AS
SELECT a.MemberId,a.CityId,b.Name as CityName FROM Member a,City b where a.CityId=b.CityId
GO
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900