How to join a Table in SQL Server with a Flat (txt) file?

  • Hi All!

    I am in trouble... I need to join a Table in SQL Server with Flat/Text File. Flat File and Table both have the same no. of fileds and should be joined with Field ID.

    Can any one tell me how to achieve this task

    Thanks in advance.

    H@ri.

  • Check out OPENROWSET in BOL.

  • There are various things you can do here.  Import the file into a table and then do the join, use openrowset or opendatasource.  Here are a couple of examples.....

    SELECT * FROM OPENROWSET(BULK N'C:\MyFlatFile.txt', FORMATFILE = 'format_file_path' ) AS MyFlatFile

     

    BULK

    INSERT #MyFlatFile

    FROM 'D:\MyFlatFile.txt'

    WITH

    (

    FIELDTERMINATOR

    ='\t',

    ROWTERMINATOR

    = '\n',

    FIRSTROW

    = 2

    )

Viewing 3 posts - 1 through 2 (of 2 total)

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