Wednesday, April 08, 2009

SQL: Return limit Rows

In the asp.net application, i found the good way to return limit rows from data table is to use the ROWCOUNT

CREATE PROCEDURE GetContacts
(
 @ModuleID int,
 @maxrows int = 0
)
AS
 SET ROWCOUNT @maxrows

 SELECT
   ItemID,
   CreatedDate,
   CreatedByUser,
   Name,
   Role,
   Email,
   Contact1,
   Contact2
 FROM
   Contacts
 WHERE
   ModuleID = @ModuleID
For more info: http://authors.aspalliance.com/stevesmith/articles/sprowcount.asp

No comments: