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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T13:35:40+00:00 2026-05-25T13:35:40+00:00

Sql Server 2005 Table Structure CREATE TABLE [dbo].[Rate]( [RateID] [bigint] IDENTITY(1,1) NOT NULL, [PairID]

  • 0

Sql Server 2005

Table Structure

CREATE TABLE [dbo].[Rate](
[RateID] [bigint] IDENTITY(1,1) NOT NULL,
[PairID] [bigint] NOT NULL,
[Open] [decimal](18, 4) NOT NULL,
[Close] [decimal](18, 4) NOT NULL,
[High] [decimal](18, 4) NOT NULL,
[Low] [decimal](18, 4) NOT NULL,
[Difference] [decimal](18, 4) NOT NULL,
[Average] [decimal](18, 4) NOT NULL,
[Percentage] [decimal](18, 4) NOT NULL,
[InfoDate] [datetime] NOT NULL,
[Hourly] [bit] NOT NULL,
[CaptureDateTime] [datetime] NULL,
CONSTRAINT [PK_Rate] PRIMARY KEY CLUSTERED 
(
[RateID] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  =   ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]

I am using paging to retrive the table as such

Select  * from(
SELECT
    (ROW_NUMBER()OVER (ORDER BY InfoDate ASC)) AS RowNo,
    [RateID],
    [PairID],
    [Open],
    [Close],
    [High],
    [Low],
    [InfoDate],
    [CaptureDateTime]
From Rate
) AS T
WHERE t.RowNo 
BETWEEN 200*@PageNumber AND 200 * (@PageNumber+1)-1
ORDER BY RowNo DESC

[Question]
I need query which will gives this me table

PageNo, StartIndex(first RateId in that page), EndIndex(Last RateId in that page), StartDate(first infoDate in that page), EndDate(Last infoDate in that page).

  • 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-25T13:35:40+00:00Added an answer on May 25, 2026 at 1:35 pm

    You could try to do something like this:

    DECLARE @PageSize INT = 200
    
    ;WITH PagingInfo AS
    (
        SELECT
            RateID, InfoDate,
            ROW_NUMBER() OVER (ORDER BY InfoDate) AS RowNo
        FROM 
            dbo.Rate
    ),
    Pages AS
    (
        SELECT     
           RateID,
           InfoDate,
           RowNo,
           ((RowNo - 1) / @PageSize) AS PageNo
        FROM PagingInfo
    )
    SELECT     
        p.PageNo,
        (SELECT RateID FROM Pages p2 WHERE p2.PageNo = p.PageNo AND p2.RowNo % @PageSize = 1) AS 'First RateID',
        (SELECT RateID FROM Pages p2 WHERE p2.PageNo = p.PageNo AND p2.RowNo % @PageSize = 0) AS 'Last RateID',
        (SELECT InfoDate FROM Pages p2 WHERE p2.PageNo = p.PageNo AND p2.RowNo % @PageSize = 1) AS 'First InfoDate',
        (SELECT InfoDate FROM Pages p2 WHERE p2.PageNo = p.PageNo AND p2.RowNo % @PageSize = 0) AS 'Last InfoDate'
    FROM Pages p 
    WHERE p.RowNo % @PageSize = 0
    

    The two CTE’s basically do the same as you did – they provide paging for the data. The second CTE Pages additionally provides the page number for each row.

    From those CTE’s, I select the relevant into – the page number (from Pages), and the first and last RateID and InfoDate for each page. This works because:

    • the first row of every page has a row number that’s 1 above a multiple of your page size, e.g. 1, 201, 401, 601 etc. – so the remainder of an integer division by your page size will always be 1

    • the last row of every page has a row number that’s divisible by your page size (e.g. 200, 400, 600 etc. ) and thus the remainder of the integer division is 0

    Based on this information, I can pick out the first and last RateID and InfoDate from the Pages CTE, for each page.

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

Sidebar

Related Questions

Let's asume I have a parent-child structure setup in SQL (server 2005): CREATE TABLE
I have a SQL Server 2005 table like this: create table Taxonomy( CategoryId integer
I wanted to modify a column in a sql server 2005 table to IDENTITY(1,1)
I have a SQL Server 2005 table called 'Contracts': CREATE TABLE Contracts ( ContractNo
Here's a table with a computed column in SQL Server 2005: CREATE TABLE footable
I have an SQL Server 2005 table that has a varchar(250) field which contains
I have a table with primary key in my MS SQL Server 2005 table.
Is it possible to force a column in a SQL Server 2005 table to
I have a nullable DateTime column in my SQL Server 2005 table called DateTimeDeleted.
I have an ADOQuery that inserts a record to SQL Server 2005 table that

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.