如何编写存储过程? [英] how to write the stored procedure?

查看:91
本文介绍了如何编写存储过程?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我有一个城市表和一个成员表。城市表包含CityID和Name.Member表包含MemberId,CityId,Name.I想要根据城市名称检索城市名称CityId通过加入两个表出现在MemberTable中。可以通过存储过程告诉我如何执行此操作吗?



谢谢..

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..

推荐答案

hi


创建程序procedureName(

@cityId int



作为

你的查询是这样的

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









- 执行程序

- pass cityId

--exec procedureName 1





--execute procedure
--pass cityId
--exec procedureName 1


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





另请访问以下链接以了解创建过程语法和SQL联接



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



http://www.w3schools.com/sql/sql_join.asp [ ^ ]


试试..

try..
CREATE PROCEDURE uspGetAddress
AS
SELECT a.MemberId,a.CityId,b.Name as CityName FROM Member a,City b where a.CityId=b.CityId
GO


这篇关于如何编写存储过程?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆