Output of a SQL Server table to an ASCII Text File

Q: How can I turn an SQL file into an ASCII text file?

A: Under Visual dBASE 7, in order to output an Interbase table (or some other SQL server table) to an ASCII text file, follow these instructions:

First, make sure you have a BDE Alias created for your SQL Database. Creating a BDE Alias is done by doing the following:

  1. Double-click the "BDE Administrator" icon in your Visual dBASE 7 folder
  2. In the left 'pane' you will see a list of BDE Aliases. To create a new one, select the "Object" menu, and then select "New ...".
  3. In the dialog that appears, select the SQL Database you need to connect to. For example, if you are using InterBase, then select "INTRBASE". Do not select the Visigenic InterBase driver -- it is buggy and does not work well.
  4. Next you will see your new alias appear in the left 'pane'.  Click on it and give it a meaningful name (other than, for example, INTRBASE1).
  5. Set the database path. For InterBase, this is on the right 'pane' in the "SERVER NAME" section. Click on the "..." button to bring up a dialog to help you find it. If you are using InterBase, you need to find the .GDB file for your database.

This is the very minimum you need to do. Select the "Object" menu again, and select "Apply" to save your changes.

Bring Visual dBASE 7 up, and:

You should see some icons at the bottom representing databases -- one of these should be named the same as your BDE Alias. Click on it. You may need to enter a password (the InterBase default password is "masterkey").

In the Command Window, type

USE tablename                                                     (where tablename is the name of the table)
COPY TO "textfile.txt" DELIMITED      (where "textfile.txt" is the name of your text file)

If you do not want quotes around your character fields, and commas between all fields, you may want to use "SDF" instead of "DELIMITED" in the statement shown above.

Your table should be in a standard format now, and readable by other software.