Cry How to...
Export Data to a Comma Separated File
To export data to a comma separated file (csv), use the bcp command line utility:
bcp [<database_name.>[<owner>].]<table_name> out <csv-file> [/U<username>] [/P<password>] [/S<server_name>] /c /t,
is an optional parameter specifying the name of the database. It can only be omitted if the desired database is the default database.
the name of the table owner.
the name of the table.
The name of the comma separated file to generate.
The SQL Server username to use. This can be left blank if NT authentication is used.
The password to use for the account.
The name of the server on which the database resides. This can be omitted if the database is on the local machine (i.e. the same machine. as the bcp command is issued from).
bcp mydb.dbo.sales out sales.csv /U /P /Ssales_svr /c /t,
bcp mydb..resellers out resellers.csv /U /P /Ssales_svr /c /t,
These notes have been tested against SQL Server 7.
About the author: Brian Cryer is a dedicated software developer and webmaster. For his day job he develops websites and desktop applications as well as providing IT services. He moonlights as a technical author and consultant.