SQL Server Performance

Row ID Variable

Discussion in 'Getting Started' started by vcs161, Aug 17, 2009.

  1. vcs161 New Member

    I need to run a select with multiple time stamps to one order ID then order them by time stamp in ascending order. That part is fine and straight forward. How can I assign a row ID or ranking number for each order ID? Then I need to do this again for another set of timestamps for the same order ID's, In the end I need to map my set from results 1 (PB) to resutls 2 (PL)and map the assigned row ID and order ID. I need to do the best I can to keep each time stamps sets together for each orderID.
    Raw Data may be like so:
    OrderIDTimeTypeTimestamp
    12345PB5:00 AM
    12345PB8:00 AM
    12345PB7:20 AM
    12345PB6:15 AM
    12345PL5:20 AM
    12345PL6:30 AM
    12345PL8:15 AM
    12345PL7:45 AMSo, in the end I need to createe the timestamps set like this
    OrderID Time IN(PB) Time Out (PL)
    12345 5:00 AM 5:20 AM
    12345 7:20 AM 7:45 AM
    12345 8:00 AM 8:15 AM
    12345 6:15 AM 6:30 AM
    Would this be a while loop? I can't write stored procedures so can this be done in an sql select?
  2. FrankKalis Moderator

    Welcome to the forum!
    If you are on SQL Server 2005 or above have a look at the ROW_NUMBER() function in the online help.
  3. vcs161 New Member

    I write SQL code in Embarcardero Rapid SQL and that does not seem to be a syntax that works there.

Share This Page