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

The Archive Base Latest Questions

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

I am storing price data events for financial instruments in a table. Since there

  • 0

I am storing price data events for financial instruments in a table. Since there can be more than one event for the same timestamp, the primary key to my table consists of the symbol, the timestamp, and an “order” field. When inserting a row, the order field should be zero if there are no other rows with the same timestamp and symbol. Otherwise it should be one more then the max order for the same timestamp and symbol.

An older version of the database uses a different schema. It has a unique Guid for each row in the table, and then has the symbol and timestamp. So it doesn’t preserve the order among multiple ticks with the same timestamp.

I want to write a T-SQL script to copy the data from the old database to the new one. I would like to do something like this:

INSERT INTO NewTable (Symbol, Timestamp, Order, OtherFields)
SELECT OldTable.Symbol, OldTable.TimeStamp, <???>, OldTable.OtherFields
FROM OldTable

But I’m not sure how to express what I want for the Order field, or if it’s even possible to do it this way.

What is the best way to perform this data conversion?

I want this to work on either SQL Server 2005 or 2008.

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

    This looks like a job for… ROW_NUMBER!

    INSERT INTO NewTable (Symbol, Timestamp, Order, OtherFields)
    SELECT
        ot.Symbol, ot.TimeStamp,
        ROW_NUMBER() OVER
        (
            PARTITION BY ot.Symbol, ot.Timestamp
            ORDER BY ot.SomeOtherField
        ) - 1 AS Order,
        ot.OtherFields
    FROM OldTable ot
    

    The PARTITION BY means that row numbers are unique for each group of Symbol and Timestamp. The ORDER BY specifies in what order the sequence is generated.

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

Sidebar

Related Questions

I have on my database a table with one column storing XML data. Due
We're storing some Guid's in a MS SQL database. There's some legacy code that
What is the advantage in storing data as an object instead of storing them
What's the best strategy for storing e-commerce product information (i.e. product price, current price)
I am storing data as Integers: class Something(models.Model): value = models.IntegerField(blank = True) but
I have data from a table in a database (string) that contain text and
i want to put current observablecollection data in list on button click event. bellow
Why does this code: var jQueryString=div.data > div.item > div.quantity,div.article,div.price > :input; $(jQueryString).live(click, function(event)
I am fetching data from some tables & storing it in a variable like
Storing credit card information securely and legally is very difficult and should not be

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.