It is convenient for SQL Server to export data using bcp, for example, to export Pubs.dbo.sales records into Excel format, and at the command prompt, enter:
(1) Specify table or view name export
BCP pubs.dbo.sales out c:\exp.xls-w-S testdb-u "sa"-P "password"
(2) Using SELECT query statements to generate data to mourn out
BCP "SELECT * from Pubs.dbo.sales" queryout c:\exp.xls-w-S Testdb-u "sa"-P "password"
Parameter description:
-S is followed by the SQL Server service name, which is executed on the database server and is not required for this parameter.
-U is followed by user name, note that the parameter is large under
The password is entered after-p
If you are executing on a server, you can use Windows trust relationships with the-t parameter
BCP "SELECT * from Pubs.dbo.sales" queryout c:\exp.xls-w-S TESTDB-T
Using BCP to guide SQL Server data to an Excel file