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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T19:19:26+00:00 2026-05-17T19:19:26+00:00

I have a set of tables in SQL Server 2005 which contain timeseries data.

  • 0

I have a set of tables in SQL Server 2005 which contain timeseries data. There is hence a datetime field and a set of values.

CREATE TABLE [dbo].[raw_data](
    [Time] [datetime] NULL,
    [field1] [float] NULL,
    [field2] [float] NULL,
    [field3] [float] NULL
)

The datetime field is unfortunately not a unique key, and there appear to be a lot of datetime values with multiple (non-identical) entries – hence DISTINCT doesn’t work.

I want to select data from these tables for insertion into a new, properly indexed table.

Hence I want a select query that will return a dataset with a single row entry for each Time. I am not concerned which set of values is selected for a given time, as long as one (and only one) is chosen.

There are a LOT of these tables, so I do not have time to find and manually purge duplicate values, so a standard HAVING COUNT(*)>1 query is not applicable. There are also too many duplicates to just ignore those time values altogether.

Any ideas? I was thinking of some kind of cursor based on PARTITION BY, but got stuck beyond that point.

  • 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-17T19:19:26+00:00Added an answer on May 17, 2026 at 7:19 pm

    You don’t need a cursor:

    SELECT tmp.*
    FROM
    (
        SELECT *, ROW_NUMBER() OVER (PARTITION BY [Time] ORDER BY [Time]) AS RowNum
        FROM raw_data
    ) AS tmp
    WHERE tmp.RowNum = 1
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We have mirroring set up between 2 SQL Server 2005 standard editions. There are
I have a table in SQL Server 2005 which contains some changelog data for
i have this procedure for inserting rows in tables(sql server 2005) CREATE PROCEDURE ans_insert
We use calculated columns in a few SQL Server 2005 tables which always return
I have a column in the database (SQL Server 2005) that has data with
We have an Access DB which has a set of local tables and input
I have a server (SQL Server 2005) with multiple archive databases (1 per quarter
I have a table in SQL Server 2005, as follows, say, fields A, B,
I have SQL Server 2005 Standard Service Pack 2 9.00.4053.00 (Intel X86) Table has
Working in SQL Server 2005, I have a stored procedure that inserts a record

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.