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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T15:19:21+00:00 2026-05-13T15:19:21+00:00

My company needs to write a query that determines when data is being entered

  • 0

My company needs to write a query that determines when data is being entered inaccurately. We have a table in our db called “ProductChanges”. It looks (something) like this –

Product    User     ChangeDate         OldValue     NewValue
2344       John     24/01/10 10:00         2344         4324
6435       Greg     28/01/10 13:30          543         6435
6532       Tony     29/01/10 09:45       <NULL>          234

When OldValue is <NULL>, it means that it is a new product record. We expect there will be a number of changes within the first hour of a record creation, as all the data is updated. But any changes after that are considered to mean the initial record was inaccurately recorded.

SO…what I am trying to come up with is a query that returns all product records created within the last month, that have any subsequent changes recorded an hour after the initial record was created. For output, we want the initial record plus all subsequent changes. Eg. –

Product    User     ChangeDate         OldValue     NewValue
6532       Tony     29/01/10 09:45       <NULL>          234
6532       Fred     01/02/10 11:37          234         4324

Thanks in advance!

Update: We are running this database on SQL Server 2000

  • 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-13T15:19:21+00:00Added an answer on May 13, 2026 at 3:19 pm

    Looks pretty straightforward, if I’m understanding correctly – just get the entry dates and join with any changes that happened more than a hour later.

    SELECT pc.Product, pc.User, pc.ChangeDate, pc.OldValue, pc.NewValue
    FROM
    (
        SELECT Product, ChangeDate AS EntryDate
        FROM ProductChanges
        WHERE OldValue IS NULL
    ) e
    INNER JOIN ProductChanges pc
        ON pc.Product = e.Product
    WHERE EXISTS
    (
        SELECT 1
        FROM ProductChanges
        WHERE Product = e.Product
        AND ChangeDate > DATEADD(HOUR, 1, e.EntryDate)
    )
    AND e.EntryDate >= @BeginDate
    AND e.EntryDate <= @EndDate
    

    We only need the second join because you mention you want the entire history for all of the “problem” sets; if you just want the IDs, you can make this query more efficient by eliminating the middle join and just selecting e.Product.

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

Sidebar

Ask A Question

Stats

  • Questions 284k
  • Answers 284k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer As far as I have been able to find out… May 13, 2026 at 4:26 pm
  • Editorial Team
    Editorial Team added an answer You can just add a subview (a UIImageView) to the… May 13, 2026 at 4:26 pm
  • Editorial Team
    Editorial Team added an answer Update: good points in the comment. So, on a second… May 13, 2026 at 4:26 pm

Related Questions

My company needs to allow the internal users of our application to write queries
I have a query that I'm not sure how to write. I'm not a
I have 3 tables 1) tblPurchaser having 2 columns: PurchaserId PurchaserName 1 A1 2
I received a client application, using SQL Server 2005, which contains many views with
After reading E-myth Revisited, I realize that I can do a better job at

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.