Writing Data from Table to many Data files

  • How to write data from SQL Server table to number of data files using stored procedure. (need to exec this procedure from third party ETL tool)

    I'm looking for something as follows:

    OPEN CURSOR

    SELECT * FROM TABLE1

    WHERE key1 = CURSOR.var1

    Create a file with TABLE1.Col1 as file name

    OPEN FILE for writing

    INSERT INTO file

    CLOSE FILE

    CLOSE CUSOR

    Thanks in advance for your help.

    Ram Chigurupati


    Ram Chigurupati

  • Unfortunately, SQL does not have a direct TSQL method at this point (I know at least one person has put on the wishlist but send a wishlist request yourself for the future). Anyway at this point you can use xp_cmdshell to access BCP to export or build a DTS package and call it to do the job. Unless the filenames are always the same and in the same location using xp_cmdshell to call the BCP cmdline tool will most likely be you best bet. If they are always the same filename and path to file then DTS will offer an eaiser to implement method. Try searching this site for threads on

    procedure AND (dts OR bcp)

    There are just so many ways including sp_OA... that can access DTS that it is a matter of finding what suits you. The above search criteria will provide lots of information in threads, articles, and tips that can help you find your solution.

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

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