• Lowell (8/27/2008)


    here's my suggestion:

    add a folder which contains all of your .csv files as a linked server.

    a text linked server will show evert .txt file and every.csv file as a table...

    so you can do something really simple like

    SELECT *

    INTO NEWTABLE

    FROM TxtSvr...sample#csv

    which would create the table on sql server with the same structure.

    i think csv files assume the first row in the file is the name of the columns.

    here's the syntax:

    --===== Create a linked server to the drive and path you desire.

    EXEC dbo.sp_AddLinkedServer TxtSvr,

    'Jet 4.0',

    'Microsoft.Jet.OLEDB.4.0',

    'C:\',

    NULL,

    'Text'

    GO

    --===== Set up login mappings.

    EXEC dbo.sp_AddLinkedSrvLogin TxtSvr, FALSE, NULL, Admin, NULL

    GO

    --===== List the tables in the linked server which is really a list of

    -- file names in the directory. Note that the "#" sign in the

    -- Table_Name is where the period in the filename actually goes.

    EXEC dbo.sp_Tables_Ex TxtSvr

    GO

    --===== Query one of the files by using a four-part name.

    SELECT *

    FROM TxtSvr...sample#csv

    --===== Drop the text server

    EXEC dbo.sp_DropServer 'TxtSvr', 'DropLogins'

    GO

    Heh... looks real familiar... 🙂

    --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)