SQL to TXT export batchfile


I needed to export a number of tables from a SQL server to text files today. BCP is great but doesn’t include header information which I needed. With some help from a couple of internet posts I wrote this batch file which worked great. It will take all the tables from a database (edit batch file to specify the database name) and export them to separate pipe delimited files. You can change the delimiter by replacing the two ^| with , if you want comma-delimited. It will also pause after creating the list of tables and open a notepad of all of the tables allowing you to remove any tables that don’t need to be exported (in my case they had a few tables containing binary attachments). Existing files are NOT overwritten allowing you to restart if needed.

,