Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6676667
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T04:01:12+00:00 2026-05-26T04:01:12+00:00

Due to the first two comments I’ve removed all my own code and placed

  • 0

Due to the first two comments I’ve removed all my own code and placed the example directly from 4 guys here.

I’m interested in how the ‘select @first_id’ should be coded. The example shows the rows being pulled using joins and I would expect that the first_id wouldn’t be a valid place to start because it doesn’t use the same join syntax.

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 
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T04:01:15+00:00Added an answer on May 26, 2026 at 4:01 am

    You can to efficient paging using ROW_NUMBER()

    DECLARE @skipRows Int = 10 --Change to input parameter to sp
    DECLARE @takeRows Int = 20 --Change to input parameter to sp
    
    SELECT *
    FROM (
        SELECT 
             ROW_NUMBER() OVER (ORDER BY a.DateCreated) As RowNumber, 
             a.PKID, 
             a.AlertUrl, 
             a.AlertDescription, 
             a.Users_PKID_creator, 
             dbo.Users_GetFullName(a.Users_PKID_creator) as Users_FullName,
             a.Dealers_PKID, 
             d.Dealer,
             dbo.convertDateFromUTC(a.DateCreated, @dealers_pkid) as DateCreated,
             dbo.convertDateFromUTC(a.DateCreated, @dealers_pkid) as ComparisonDate,
             dbo.convertDateFromUTC(a.DateModified, @dealers_pkid) as DateModified,
             a.Active,
             a.Contacts_PKID,
             dbo.Contacts_GetFullName(a.Contacts_PKID) as Contacts_FullName
    from     Alerts a
    join     Dealers d on d.PKID = a.Dealers_PKID
    where    a.DateCreated between dbo.convertDateToUTC(@datetimeDateStart, @dealers_pkid) and dbo.convertDateToUTC(@datetimeDateEnd, @dealers_pkid)
    and      a.Active = @bitActive
    and      a.PKID >= @first_id
        ) AS [t1]
    WHERE [t1].RowNumber BETWEEN @skipRows + 1 AND @skipRows + @takeRows 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've taken my first baby steps into Unit Testing and, due to a better
We have an SVN at http:/XX.XXX.XXX.XXX:1111/svn/AB/ - and the first two folders of the
I have two .php files which show all contacts in a database, then allows
I have created two projects. The first one, extracts information of handset and shows
So we have two automated processes on our build system. The first performs an
I have to extract two random records from a table. I have implemented something
I'm concerned about my Java client directly connecting to the MySQL server due to
I'm currently facing strange problems with Android's font Roboto. At first I had two
I have two tables, XMLtable and filterTable . I need all the XMLtable.ID values
i want to pass data between two activities.In the first activity i m using

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.