spool output to particular file from command prompt

删除回忆录丶 提交于 2019-12-11 13:05:04

问题


I want to spool my output to a particular file. My database in SqlServer. I am entering code in command prompt like this:

First I am connecting to my data base like this:

sqlcmd -S SUPPORT2/SUPPORT2 -U sa -P solutions

SUPPORT2/SUPPORT2 is a my server name.
I choose my database name(vallett), then I am selecting Ename from EmployeeMaster_tbl.
I want to spool this output to a particular word file, how can I do this?

I tried somthing like this..but getting an error


回答1:


-o is a parameter for the call of sqlcmd a call could look like this

sqlcmd -S SUPPORT2/SUPPORT2 -U sa -P solutions -Q " SELECT Ename from Vallett.dbo.EmployeeMaster_tbl" -o C:\temp\test.txt 

Make shure the destination file can be written (C:\txt1.txt might not be possible)

If you want to create the output file interactive you can use :OUT to redirect the output to a file and reset ist to stdout. An example could look like this:

 sqlcmd -S SUPPORT2/SUPPORT2 -U sa -P solutions 
 use Vallett
 GO
 :OUT C:\temp\test.txt
 SELECT Ename from dbo.EmployeeMaster_tbl
 GO
 :OUT stdout


来源:https://stackoverflow.com/questions/18556073/spool-output-to-particular-file-from-command-prompt

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!