Copy comma delimitted text file to a table by ascending order

  • Once again.

    It does not matter which order you use to insert data into a table.

    In most cases it will be resided in the table in different order (depending on table definitions - constraints, idexes, etc.)

    And physical order of records in a table does not match order of records returned by SELECT statement. It may be the same for simple queries on small recordsets (as your test one). But it's not the case on real life systems.

    So, abandon your attempts to sort records on INSERT. It's absolutely useless exercise.

    Think how to define the order of records on SELECT.

    _____________
    Code for TallyGenerator

  • Sergiy,

    Can you give me some idea using Select? appreciate your help

    Thx

  • He already did... 😉

    SELECT *

    FROM #NewTempTable

    ORDER BY ID

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.

    Change is inevitable... Change for the better is not.


    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)

  • I don't want all the rows to be order by that is the thing right. i want only set of rows order by:)

    Thx

  • vkres1 (8/3/2008)


    I don't want all the rows to be order by that is the thing right. i want only set of rows order by:)

    Thx

    What in your rows groups them into sets?

    How can SQL Server tell which rows belong to one set and which to another one?

    _____________
    Code for TallyGenerator

  • sergiy,

    suppose if the C1 = 42 then end of the first set. what i want is i just want to move that row 42 above the 51 in that set so that all will be in the order like

    C1 C2 C3

    41 te ce

    42 te ce

    51 te ce

    41 te ce

    42 te ce

    51 te ce

    and so on.........

  • What about the out of place 41?

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.

    Change is inevitable... Change for the better is not.


    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)

  • The row starts with 41

  • vkres1 (8/4/2008)


    The row starts with 41

    Heh... Ya Think? What do you want to do with it? 😉

    Have you tried the clustered index solution I gave you yet? :blink:

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.

    Change is inevitable... Change for the better is not.


    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)

Viewing 9 posts - 16 through 23 (of 23 total)

You must be logged in to reply to this topic. Login to reply