Save SELECT query output to a text file
2008-04-02 13:54
309 查看
Well use xp_cmdshell. xp_cmdshell is an extended stored procedure kept
in the master database. It issues OS commands directly to the Windows
command shell. You need to be a member of the sys_admin group to use
this command or have the xp_sqlagent_proxy_account.
To save your SELECT query results to a text file, use this query :
EXEC master..xp_cmdshell'bcp "SELECT TOP 5 CUSTOMERID FROM Northwind.dbo.Customers" queryout "c:"text.txt" -c -T -x'
One
word of caution. xp_cmdshell operates synchronously. So the caller has
to wait for the control to be returned to him/her until the
command-shell command is completed.
Note: By default,
xp_cmdshell is disabled in SQL 2005 for security reasons. To enable it,
use the Surface Area Configuration tool or sp_configure. To enable
xp_cmdshell using sp_configure, use this query :
EXEC master.dbo.sp_configure 'show advanced options', 1
RECONFIGURE
EXEC master.dbo.sp_configure 'xp_cmdshell', 1
RECONFIGURE
相关文章推荐
- Save output to a text file from Mac terminal
- Save or append text to a file (c#)
- Linux command: save the output of a command to a file
- Save MySQL query results into a text or CSV file
- SaveTextFile - Save or append text to a file
- Save MySQL query results into a text or CSV file
- Failed to save package file--Integration Services
- ORA-07391: sftopn: fopen error, unable to open text file
- Lua Save Table to File
- How to read text file in client side via HTML5
- Convert between windows text file to Unix type
- How to redirect the output of DBMS_OUTPUT.PUT_LINE to a file
- How to save cookie in file for Requests
- How to get file name when user select a file via <input type=“file” />?
- Could not write to output file 'c:/WINDOWS/Microsoft.NET/Framework/v2.0.5072的处理
- [整理]VC编译程序时出现the source files are both configured to produce the output file....
- mt.exe : general error c101008a: Failed to save the updated manifest to the file
- Code: Writing Text to a File (Visual Basic)
- SaveVarToFile
- SQL Script for select data from ebs and make a csv file to FTP