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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T08:09:16+00:00 2026-05-20T08:09:16+00:00

I have a table that tracks price data over time for various goods. Here’s

  • 0

I have a table that tracks price data over time for various goods. Here’s a simplified example:

Table name [Product_Prices]

PRODUCT DATE PRICE
------------------
Corn 1/1/2011 1.35
Corn 1/2/2011 1.40    
Corn 1/3/2011 1.40    
Corn 1/4/2011 1.50    
Beef 1/1/2011 1.35    
Beef 1/2/2011 1.15    
Beef 1/3/2011 1.15    
Beef 1/4/2011 1.30    
Beef 1/5/2011 1.30    
Beef 1/6/2011 1.35

I want a query that pulls the earliest date that the prices changed, for each instance where the price actually did change. Based on the sample table above, this is the output I want:

PRODUCT DATE PRICE
------------------    
Corn 1/1/2011 1.35    
Corn 1/2/2011 1.40    
Corn 1/4/2011 1.50    
Beef 1/1/2011 1.35    
Beef 1/2/2011 1.15    
Beef 1/4/2011 1.30    
Beef 1/6/2011 1.35

I am currently doing it in a cursor but it’s incredibly inefficient and I feel that there must be a simpler way to get this data. The table I’m working with has about 2.3 million records.

SQL 2000

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-20T08:09:16+00:00Added an answer on May 20, 2026 at 8:09 am

    SQL is, unfortunately, not a language that’s well-suited to working with ordered sets (relational databases are great for it, but the SQL language is not). Additionally, some of the T-SQL features that make working with these sets easier (ROW_NUMBER(), for example) were not introduced until SQL Server 2005.

    Given the restriction to SQL Server 2000, you’ll have to do something like this:

    select
        pp.Product,
        pp.Date,
        pp.Price
    
    from Product_Prices pp
    
    where pp.Price <> (select top 1 
                           pp2.Price 
    
                       from Product_Prices pp2 
    
                       where pp2.Date < pp.Date 
                         and pp2.Product = pp.Product 
    
                       order by pp2.Date desc)
    

    (I don’t have SQL Server 2000 available to test, but I believe this should function correctly on 2000)

    This will retrieve every row from Product_Prices where the price for that product is not equal to the previous record for that product.

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

Sidebar

Related Questions

I have a History Table in SQL Server that basically tracks an item through
I have a table that has redundant data and I'm trying to identify all
I have a table that tracks serial numbers and the number of licenses associated
I'm working in Sql Server 2005. I have an event log table that tracks
Currently we have a table that we use to track inivitations. We have an
I have a table that got into the db_owner schema, and I need it
I have a table that contains tasks and I want to give these an
I have a table that records a sequence of actions with a field that
I have a table that is created in a DataList in ASP.Net. This table
I have a table that holds information about cities in a game, you can

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.