Output to text-file

How can I get data from table to text-file by SQL-commands, for example
SELECT * FROM Table. Result to text-file Table.txt.
Kaitsu [ So, 13 Januar 2008 08:46 ] [ ID #1906557 ]

Re: Output to text-file

On Sun, 13 Jan 2008 07:46:39 GMT, "Kaitsu" <Kaitsu [at] luukku.com> 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
Roy Harvey [ So, 13 Januar 2008 09:58 ] [ ID #1906558 ]

Re: Output to text-file

"Kaitsu" <Kaitsu [at] luukku.com> wrote in news:zljij.17$kS4.0 [at] 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
Chris.CheneyXXNOSPAMX [ So, 13 Januar 2008 10:55 ] [ ID #1906559 ]
Datenbanken » comp.databases.ms-sqlserver » Output to text-file

Vorheriges Thema: Queries Log on SQL Server 2000 ???
Nächstes Thema: check the word whether correct or not