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 6843557
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T00:15:33+00:00 2026-05-27T00:15:33+00:00

I was wondering if you could do something like this is Microsoft SQL Server

  • 0

I was wondering if you could do something like this is Microsoft SQL Server 2k8 R2

Say I have a query which returns 100 rows of data.

Is their a way I can pass in some variables for example @lower_limit and @upper_limit.

Then I want the query to record the rows between the lower and upper limit

For example:

@lower_limit = 5
@upper_limt  10

Would return me rows 5 – 10 from the 100 records.

  • 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-27T00:15:34+00:00Added an answer on May 27, 2026 at 12:15 am

    You can assign a ROW_NUMBER() over your result set and then use the BETWEEN statement to limit the rows.

    A contrived example:

    WITH data AS
    (
        SELECT
            ID
           ,YourColumn
           ,ROW_NUMBER() OVER (ORDER BY ID) AS RowNum
        FROM
            YourTable
    )
    SELECT 
        *
    FROM
        data
    WHERE
        RowNum BETWEEN 5 AND 10
    

    EDIT: For standard paging, here’s exactly the technique I use in all the applications I develop:

    DECLARE @PageNumber int = /* The page number you want */
    DECLARE @PageSize int = /* The number of records per page */
    WITH paged AS
    (
        SELECT
             ROW_NUMBER() OVER(ORDER BY [OrderByColumns]) AS RowNum
            ,*
        FROM
            [YourSource]
    )
    SELECT 
         [Column1]
        ,[Column2]
        ,...
    FROM 
        paged
    WHERE 
        RowNum BETWEEN (@PageNumber - 1) * @PageSize + 1 AND @PageNumber * @PageSize
    ORDER BY 
        [OrderByColumns] -- Same as used in ROW_NUMBER()
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I was wondering how I could do something like this ( source ) using
Say I have an entity that looks something like this simple example: MyEntity {
I'm wondering if arrays in Java could do something like this: int[] a =
In rails I could do something like this to make sure a user is
Good evening, I was wondering if I could do something like: while(true) { MyEnum
In rails 2.3.5 you could do something like this inside the routes.rb file: map.root
Wondering if I could get some advice and direction on this following requirement: Need
I was wondering if anyone could tell me if this kind of behaviour is
I am trying to build a TreeView and have it set up like this
I am experimenting with scope extensions and was wondering if I could do something

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.