/ Published in: SQL
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
CREATE PROCEDURE [dbo].[usp_PageResults_NAI] ( @startRowIndex INT, @maximumRows INT ) AS DECLARE @first_id INT, @startRow INT -- A check can be added to make sure @startRowIndex isn't > count(1) -- from employees before doing any actual work unless it is guaranteed -- the caller won't do that -- Get the first employeeID for our page of records SET ROWCOUNT @startRowIndex SELECT @first_id = employeeID FROM employees ORDER BY employeeid -- Now, set the row count to MaximumRows and get -- all records >= @first_id SET ROWCOUNT @maximumRows SELECT e.*, d.name AS DepartmentName FROM employees e INNER JOIN Departments D ON e.DepartmentID = d.DepartmentID WHERE employeeid >= @first_id ORDER BY e.EmployeeID SET ROWCOUNT 0 GO
URL: http://www.4guysfromrolla.com/webtech/042606-1.shtml