Reputation: 3645
I am executing a bunch of SQL scripts using SQLCMD
, and redirecting the output to a log file using the -o
switch. How do I turn off the output of SELECT queries? Errors, if any, should still be written to the log file, as usual.
Upvotes: 2
Views: 8111
Reputation: 367
$ sqlcmd -S server -d database -E -r0 -Q "select 1" 1> NUL 2> NUL
-Q
allows you to specify your query.
1>
is for the stdout. You can use 1> logs.txt
instead to write the output into a file.
2>
is for the stderr. You can use 2> errors.txt
instead to write the errors into a file.
Further reading is available on sqlcmd reference from Microsoft.
Upvotes: 3
Reputation: 21505
If you want to log only errors, log by redirecting STDERR
rather than by using the -o
switch:
SQLCMD -S server -d database -E -r0 -Q "select 1" 2> error.log
update
Added that the -r0
switch must be set to redirect errors to STDERR
Upvotes: 2