Help importing txt files

  • Hi,

    I'm having problems in figuring out why an ordered txt file doesn't have, after importing to SQL server using DTS, the same order in the table it created.

    I have a cursor that only works with an ordered file, and everytime I import a file to use the cursor in, it appears unordered preventing the program to perform well.

    Can anyone help me?

    Thanks

     

  • You need to ad an 'order by' clause to the cursor definition if you want the rows back in a particular order.  Relational tables have no implied order and unless an 'order by' is specified, data can be returned in any manner convenient for the DBMS. 


    And then again, I might be wrong ...
    David Webb

  • Also see "Clustered Indexes" in BooksOnLine.

    Greg

    Greg

  • I tried to do that, but the cursor doesn't work.

    Declaration of the cursor:

    DECLARE C1 CURSOR

    FOR SELECT consumer_fidelity_card, basket, dia

        FROM  dbo.teste_freq

        ORDER BY consumer_fidelity_card

    FOR UPDATE OF dias

     

    Error message:

    FOR UPDATE cannot be specified on a READ ONLY cursor.

     

  • Can you start this from the begining??

    What do you have to do exactly?

  • You cannot use the FOR UPDATE unless every row in your cursor is unique...

    Try adding an IDENTITY column to this table and re-run this procedure.  Your update of a single row would attempt to update multiple rows... this error is due to poor table design.

    -Mike Gercevich

  • I assume there is no "line number" or other incrementing number in your text file - add an identity field to the table and then order your cursor based on the identity field...

    Actually the prior answer sort of says this, but I imagine that you want the specific order of rows in the text file - without the identity in the table for the insert, the rows, as they are inserted, will not stay in any particular order and without an existing column from your text file to order them by you would be out of luck.  So add the identity field and see if it keeps the order for you.

    Good luck

Viewing 7 posts - 1 through 6 (of 6 total)

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