BULK INSERT MESS UP

  • THIS STATEMENT WORKS FINE BUT ON THE FINAL TABLE THE RECORDS ARE ALL OUT OF THE ORDER FROM THE ORIGINAL TXT FILE..SOMEBODY NOW WHY?

    set @SQL ='BULK INSERT temp FROM ''' + @file1 + ''' WITH (FIELDTERMINATOR = ''\T'') '

  • This was removed by the editor as SPAM

  • Is there an index forcing a sort on the data? That is the only thing that I can think of.

    David

    David

    @SQLTentmaker

    “He is no fool who gives what he cannot keep to gain that which he cannot lose” - Jim Elliot

  • If your in coming data is sorted according to the index specified in the destination table you get will sorted data. If, however, the data file is sorted in different order or no order is specified records will inserted randomly.

  • There is no 'order of records' in a relational database. Even if SQL Server does apply some rules concerning the way in which the data is returned (in order of clustered key, I believe), you should not rely on this 'feature'.

    Use a SORT clause in your query to return the records in the order you want them to be returned.

Viewing 5 posts - 1 through 4 (of 4 total)

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