Creating Multiple Text Files from a result set.

  • All,

    I have a large result set which return data for a 100's of customers with various information.

    I am currently looping on this result set by customer and writing the records to a text file using

    bcp. This can be slow as i have to loop quite a number of times. I was wondering does anyone

    know a method where i could write all the records at once to multiple files or else they may

    know of a utility where I can write the original record set to one file and use this utility to

    split the files many times. Any help on this would be appreciated.

    Thanks.

  • Do the following:

    1. change the result mode to "Results to File [CTRL + SHIFT + F]".

    2. Execute the query in the SQL query window.

    3. It will ask the file name where to store the resultset.

    4. supply the path with filename

    kshitij kumar
    kshitij@krayknot.com
    www.krayknot.com

  • Thanks. However this is running in a batch job and not from query analyzer. Its running in a nightly process within a stored procedure.

    Thanks again anyways.

  • But by using BCP you can also export the data to an external file at once.

    EXEC master..xp_cmdshell 'bcp "select * from Databasename.dbo.tablename" queryout "c:\text.txt" -c -T -x'

    might be this link is helpful

    http://www.sqlteam.com/article/exporting-data-programatically-with-bcp-and-xp_cmdshell

    kshitij kumar
    kshitij@krayknot.com
    www.krayknot.com

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

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