首页 > 数据库

Stored Procedures: Returning Data

时间:2009-04-23 12:54:32  作者:武树伟  我要投稿
Linux初探欢迎您的投稿,投放方法请点击这里查看,我们会定期赠送精美小礼品给优秀的投稿作者。海纳百川 取则行远!LinuxGoo欢迎您的到来。
Stored Procedures: Returning DataBy Bill Graziano on 09 April 2001This article discusses three common ways to return data from stored procedures: ret......

Stored Procedures: Returning Data

By Bill Graziano on 09 April 2001


This article discusses three common ways to return data from stored procedures: returning result sets (SELECT statements), using output variables and using the RETURN statement. Each example includes client-side code (ASP.NET) and server-side code (T-SQL) to read the results. (This article has been updated through SQL Server 2005.)


All the examples in this article use the AdventureWorks database and have been tested through SQL Server 2008. All the client code examples are written using ASP.NET 2.0.

Result Sets

Result sets are what you get when you run a simple SELECT statement inside a stored procedure. Let's suppose you want a stored procedure to return a list of all the people with a given last name. The code for the stored procedure might look like this:

CREATE PROCEDURE dbo.GetPeopleByLastName (@LastName NVARCHAR(50))

AS

SELECT ContactID,

    FirstName,

    LastName

FROM Person.Contact

WHERE LastName = @LastName

ORDER BY ContactID

If you just execute this stored procedure in SQL Server Management Studio you get a result set that looks like this:

EXEC dbo.GetPeopleByLastName @LastName = 'Alexander'



- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 



  ContactID FirstName                           LastName

----------- ----------------------------------- -----------------------

         22 J. Phillip                          Alexander

         23 Michelle                            Alexander

        430 Mary                                Alexander

        

 . . . { hiding a bunch of rows } . . .

 

      19942 Morgan                              Alexander



(123 row(s) affected)
如果您需转载 Stored Procedures: Returning Data,请注明来自LinuxGoo.com,其版权归原作者所有。请广大网友留言时遵纪守法,使用文明用语。如果您在应用中有什么问题,请在下面留言,我们会尽快解答。
来顶一下
近回首页
返回首页
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表
相关文章
栏目热门