Output to text-file

Output to text-file

am 13.01.2008 08:46:39 von Kaitsu

How can I get data from table to text-file by SQL-commands, for example
SELECT * FROM Table. Result to text-file Table.txt.

Re: Output to text-file

am 13.01.2008 09:58:36 von Roy Harvey

On Sun, 13 Jan 2008 07:46:39 GMT, "Kaitsu" wrote:

>How can I get data from table to text-file by SQL-commands, for example
>SELECT * FROM Table. Result to text-file Table.txt.

This must be executed at a command prompt, not as a SQL query.

bcp.exe "select * from master..sysdatabases" queryout
sysdatabases.txt -c -T -t\t -r\n

There are many other parameters to consider, in particular -S to
specify the server, and -f to specify a format file. Read about it in
Books On Line.

Roy Harvey
Beacon Falls, CT

Re: Output to text-file

am 13.01.2008 10:55:41 von Chris.CheneyXXNOSPAMXX

"Kaitsu" wrote in news:zljij.17$kS4.0@read4.inet.fi:

> How can I get data from table to text-file by SQL-commands, for example
> SELECT * FROM Table. Result to text-file Table.txt.
>
>
>

From T-SQL, you could use the JET or ACE text-file drivers (if installed):

INSERT INTO OPENDATASOURCE('Microsoft.JET.OLEDB.4.0', 'Data Source=C:
\Documents and Settings\chris\My Documents;Extended
Properties="text;HDR=No"')...[test999#txt] SELECT Name, Comments FROM
Buildings


(but not SELECT ... INTO ... ); the output text file must exist and must
either have a header line, whether or not HDR=Yes or HDR=No, or there must
be a relevant entry in schema.ini. Note that the "." before the extension
in the text-file name must be replaced by "#".

Replace 'Microsoft.JET.OLEDB.4.0' by 'Microsoft.ACE.OLEDB.12.0' to use the
ACE provider (ACE is a free download from MS).

For details of schema.ini, see
http://msdn2.microsoft.com/en-us/library/ms709353.aspx (JET) or
http://msdn2.microsoft.com/en-us/library/bb177651.aspx (ACE)

I believe that it should also be possible to use the ODBC text driver, but
I have no experience of it.

HTH