First, in sqlserver Query Analyzer, execute:
EXEC master..xp_cmdshell 'bcp "SELECT * FROM [alarm] [dbo] [a_abc].." Queryout "c: \ book1.xls" -c -S "ip address" -U "username" -P "password " '
EXEC master..xp_cmdshell 'BCP test.dbo.name out d:\t_002.txt -c -t -T'
EXEC master..xp_cmdshell 'BCP "select name from test.dbo.name" queryout d:\t_004.txt -c -t -T'
EXEC master..xp_cmdshell 'BCP tran_test.dbo.uptrans out d:\t_006.txt -c -t -S HOUYAJUN\JHIDCDBS005 -T'
Note: The data is exported to the c disk server.
Second, cmd, command line execution:
bcp "SELECT * FROM [alarm] [dbo] [a_abc].." queryout "c: \ book1.xls" -c -S "ip address" -U "username" -P "password"
It will be exported to the local machine c drive.
Third, environmental requirements, export of machinery need to install sqlserver, need binn \ bcp.exe, namely environment variables which need to have:
C:\Program Files\Microsoft SQL Server\80\Tools\BINN;
Fourth, problems may occur:
Appears "Syntax Error in 'queryout'." When executing SQL bcp command wrong reasons and solutions
Internet search found because: later on this machine installed Sybase database . After installing Sybase, resulting in changed environment variables cause bcp command error.
That sybase there bcp command, covering the sqlserver bcp command, open environment variable to the binn sqlserver directory to the front.
Reference: http://penpenguanguan.com/3064.html