• I just recently had to load data in from a flat file, and had to ensure the order (well, I actually had to be able to get the first row with the column headers).

    Solution:

    BCP into a temp table with an identity column, using a format file to skip the identity column.

    Example:

    IF OBJECT_ID('tempdb..#temp') IS NOT NULL DROP TABLE #temp

    CREATE TABLE #temp (RowData varchar(8000), RowID INT IDENTITY PRIMARY KEY CLUSTERED)

    -- load the data file

    PRINT 'BULK INSERT'

    BULK INSERT #temp

    FROM 'c:\<mypath>\<MyCSVFile>.csv'

    WITH (FORMATFILE='C:\<mypath>\<MyXMLFormatFile.xml')

    --Format file:

    <?xml version="1.0"?>

    <BCPFORMAT xmlns="http://schemas.microsoft.com/sqlserver/2004/bulkload/format" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">

    <RECORD>

    <FIELD ID="1" xsi:type="CharTerm" TERMINATOR="\r" MAX_LENGTH="8000"/>

    </RECORD>

    <ROW>

    <COLUMN SOURCE="1" NAME="RowData" xsi:type="SQLVARYCHAR"/>

    </ROW>

    </BCPFORMAT>

    Hope this helps

    Wayne
    Microsoft Certified Master: SQL Server 2008
    Author - SQL Server T-SQL Recipes


    If you can't explain to another person how the code that you're copying from the internet works, then DON'T USE IT on a production system! After all, you will be the one supporting it!
    Links:
    For better assistance in answering your questions
    Performance Problems
    Common date/time routines
    Understanding and Using APPLY Part 1 & Part 2