Reading flat files from TSQL

  • Hi,

    I need to access data present in csv/txt files, say, a list of names in TSQL code.

    The ideas that come to my mind are importing the contents to a temporary table either through bulk load or DTS and use it in the TSQL.

    I wanted to know if there is any other file access command in TSQL using which I can read the data in txt file and use to process further.

    Thanks in advance.

    Best regards

    Kiran

  • With openrowset() and openquery() you can access the file directly. See the BOL for details.

  • Thanks joachim

    I think these commands are the ones I was looking for.

    Best Regards

    Kiran

  • My recommendation would be to import the data into a staging table using BULK INSERT. Nasty fast... then, you can add the necessary indexes for performance... can't do that with OPENROWSET or the like...

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

  • OPENROWSET though gives you the ability to filter in the same query. If you don't need that flexibility you should follow Jeff's advice.


    * Noel

  • You really think filtering on an OPENROWSET would be faster than just importing the table?

    --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 6 posts - 1 through 5 (of 5 total)

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