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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T19:07:07+00:00 2026-05-27T19:07:07+00:00

I’m working on a custom DAL and am now dealing with automatic result pagination.

  • 0

I’m working on a custom DAL and am now dealing with automatic result pagination. The DAL generates dynamic queries based on our models, like:

Model.All() --> generates "select * from mytable"
Model.Filter ("d=@0", "arg0value") --> generates "select * from mytable where d=@0"
...

I don’t want to add extra parameters to our filter functions, nor specialized functions for paginating (well, if it’s avoidable, of course). Instead, I’d like to paginate the results changing the query before it gets executed. Something like…

var resultset = Model.Filter ("d=@0, "arg0value"); // "select * from mytable where d=@0"
resulset = resultset.Paginate (1, 25); // this should paginate the query before loading any objects

In Oracle it’s easy, using the ROWNUM pseudocolumn and wrapping the old query.

select * from (my old sql) where rownum between 20 and 40

In Sql Server (2005) there’s nothing like ROWNUM. I’ve seen there is the ROW_NUMBER function, but it requires knowing the inners of the query, as you need to pass an “OVER (ORDER BY xxxx)” clause.

select row_number() over (order By <?????>) as rownum, dv.* from (my old sql) as dv where rownum between 20 and 40

So, is there a way to perform this in Sql Server without adding specific parameters/functions to our models?

Thanks!

Edit

As @Dems says, I could parse the query and add the ORDER BY based on the output fields, but: first, I don’t want the overhead of parsing, and second, if the query is of type “select *”, I can’t extract the fields.

  • 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-27T19:07:08+00:00Added an answer on May 27, 2026 at 7:07 pm

    If you’re writing your own data access layer, and you want to apply ROW_NUMBER() only knowing the query’s output field names (rather than it’s internals)…

    SELECT
      *
    FROM
    (
      SELECT
        ROW_NUMBER() OVER (ORDER BY field1, field2, field3) AS row_id,
        *
      FROM
      (
        <your-query>
      )
        AS unordered_data
    )
      AS ordered_data
    WHERE
      row_id BETWEEN x AND y
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a jquery bug and I've been looking for hours now, I can't
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
this is what i have right now Drawing an RSS feed into the php,
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build
Configuring TinyMCE to allow for tags, based on a customer requirement. My config is
We are using XSLT to translate a RIXML file to XML. Our RIXML contains
I'm working with an upstream system that sometimes sends me text destined for HTML/XML
That's pretty much it. I'm using Nokogiri to scrape a web page what has

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.