Exporting to Text File

  • Is it possible to create a stored procedure that inserts the results of a query into a comma separated text file?  I want to get results of a query, but I don't want to have to create a table to store them, and a view doesn't work for the query's structure.  If it is possible to export to text files through stored procedures, please let me know how.

    Thanks for the help with this, Adam

  • I may be missing the boat here, but it sounds like you may want to give a little more information.  Are you calling this SP from an application?  In that case, a SELECT statment at the end of the SP will give you a recordset, (you could insert comma's if needed).  Otherwise, this sounds like something you would do through a DTS package. 

    Others may see understand this better than I and give you a different and potentially better answer. 

    I wasn't born stupid - I had to study.

  • First of all, do not worry about this issue any more because we are not combining all servers information any more, we are breaking the query out, so I can use a DTS for that.  See, the problem with it before was that a DTS has problems retrieving the results from the query because the query is built through a loop because it had to query various linked servers then combine their information. 

    Thank you for the assistance, anyway....Adam

     

     

  • this might help you.

    http://www.motobit.com/tips/detpg_SQLWrFile/

     

    I used this approach before and it worked well. I used cursor to loop through the result query, to format and write it into text file line by line

     

  • actually that looks like exactly what I was wanting.  Thanks!

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

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