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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T09:41:43+00:00 2026-06-01T09:41:43+00:00

I am getting from database list of items ordered by descending date. I use

  • 0

I am getting from database list of items ordered by descending date.
I use ROW_NUMBER() function to get 50 by 50 items.
First time I need to get items from 1-50 than 51-100 etc.
I have in database items with type 1 and those are items that I get.
There is thousands of those items in database.
So when I first time call stored procedure I pass it number one (number from which item to get next 50).
So this should return me first 50 items. Now I add to where clause RowNum < 1+50 but row numbers that I get from query are: 35,37,38,43,44,45,55,67 etc. so my stored procedure returns me only items from 35 to 45.
I think I make some stupid miss in my query but can’t find it.

SELECT  *
FROM    ( SELECT    ROW_NUMBER() OVER ( ORDER BY Products.CreatedOnDate DESC ) AS RowNum, Products.*          
          FROM      Products          
          WHERE     Products.CreatedOnDate <= GETDATE()
        ) AS RowConstrainedResult
WHERE   RowNum >= 1
    AND RowNum < 1+50 -- here I use parameter but currently I hardcode '1'
    AND ProductTypeId = 1
ORDER BY RowNum
  • 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-06-01T09:41:44+00:00Added an answer on June 1, 2026 at 9:41 am

    You are filtering on ProductTypeID but the inner query with the Row_Number does not:

    SELECT  *
    FROM    ( SELECT   ROW_NUMBER() OVER ( ORDER BY Products.CreatedOnDate DESC ) AS RowNum
                     , Products.*          
              FROM     Products          
              WHERE    Products.CreatedOnDate <= GETDATE()
              AND      ProductTypeId = 1
            ) AS RowConstrainedResult
    WHERE   RowNum >= 1
    AND     RowNum < 1+50 
    ORDER BY RowNum
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i am getting a list of items from sqlite database and place them in
I have a method for getting values from database. public virtual List<TEntity> GetValues( int?
I am getting a list of products from my database as a BindingList. I
I am getting some data from my database table. The query I use is
I'm getting a list of review items from a web service that dictates what
I have the following two methods for getting data from my database: - (void)
Here's the problem: In C# I'm getting information from a legacy ACCESS database. .NET
Getting error while inserting values into database (SQL Server 2008) Implicit conversion from data
I'm interested in getting the SQLite database containing browsing history from the built in
I am getting directories from users and storing in databases. I really need validation

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.