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

  • Home
  • SEARCH
  • 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 1031319
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T13:54:32+00:00 2026-05-16T13:54:32+00:00

I currently use SQL2008 where I have a stored procedure that fetches data from

  • 0

I currently use SQL2008 where I have a stored procedure that fetches data from a table that then gets fed in to a line graph on the client. This procedure takes a from date and a too date as parameters to filter the data. This works fine for small datasets but the graph gets a bit muddled when a large date range is entered causes thousends of results.

What I’d like to do is provide a max amount of records to be returned and return records at evenly spaced intervals to give that amount. For example say I limited it to 10 records and the result set was 100 records I’d like the stored procedure to return every 10th record.

Is this possible wihtout suffering big performance issues and what would be the best way to achieve it? I’m struggling to find a way to do it without cursors and if thats the case I’d rather not do it at all.

Thanks

  • 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-16T13:54:33+00:00Added an answer on May 16, 2026 at 1:54 pm

    Assuming you use at least SQL2005, you could do somesting like

    WITH p as (
         SELECT a, b,
                row_number() OVER(ORDER BY time_column) as row_no,
                count() OVER() as total_count
           FROM myTable
          WHERE <date is in range>
         )
    SELECT a, b
      FROM p
     WHERE row_no % (total_cnt / 10) = 1
    

    The where condition in the bottom calculates the modulus of the row number by the total number of records divided by the required number of final records.

    If you want to use the average instead of one specific value, you would extend this as follows:

    WITH p as (
         SELECT a, b,
                row_number() OVER(ORDER BY time_column) as row_no,
                count() OVER() as total_count
           FROM myTable
          WHERE <date is in range>
         ),
        a as (
        SELECT a, b, row_no, total_count,
               avg(a) OVER(partition by row_no / (total_cnt / 10)) as avg_a
          FROM p
        )
    SELECT a, b, avg_a
      FROM a
     WHERE row_no % (total_cnt / 10) = 1
    

    The formula to select one of the values in the final WHERE clause is used with the % replaced by / in the partition by clause.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a SQL 2005 instance that runs a job that uses a Powershell
We currently use MOSS 2007 for our company intranet site and we are looking
I currently use PluralSight for online video training on .net related technologies. Their videos
I currently use the following expression which I use to put paragraph tags around
I currently use CKEditor on my website, however not every time users access the
I currently use nginx with passenger to serve my rails app. considering including a
I currently use the Android Monkey tool for stress testing Android system/packages. I find
I currently use MyIasm as my default engine, i ran mysqltuner to check some
I am using MS SQL 2008 to develop one system with Classic ASP. I
I am trying to write a classifier function for the SQL 2008 resource governor.

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.