Is there a way to suppress "x rows affected" in SQLCMD from the command line?
Asked Answered
P

3

99

Is there a way to suppress "x rows affected" in SQLCMD from the command line?

I'm running an MSBuild script and don't want it clogging up my log on my build server.

I'd rather not have to add "SET NOCOUNT ON" in every script, so if there's a way to do it from the command line, that would be fantastic.

Paulettepauley answered 6/1, 2010 at 15:47 Comment(0)
W
104

What about creating a startup script with SET NOCOUNT ON in the script (assign the script to the SQLCMDINI environment variable). http://msdn.microsoft.com/en-us/library/ms162773.aspx

Would answered 6/1, 2010 at 16:8 Comment(2)
Yep - just simply adding SET NOCOUNT ON; to your export query (or query file) will help this.Badoglio
But if the script has GO commands in it, the NOCOUNT setting will be reset after every GO will it?Rudin
D
60

The -i and -q options are mutually exclusive.

Create a file named setnocount.sql with the content:

SET NOCOUNT ON;

And you might be able to do -i setnocount.sql,otherscript.sql using the multiple files feature and effectively an "included" common first file.

Denman answered 6/1, 2010 at 21:17 Comment(0)
W
50

You can also run multiple lines in the -Q parameter, separated by semicolon, like below

eg:

-Q "set nocount on;select * from table;delete from table where some_condition=true"
Weekend answered 15/1, 2013 at 5:49 Comment(2)
Is there a way to ignore column name from the output?Macleod
you pass in -h -1 meaning you don't want headers to be printed.Witherite

© 2022 - 2024 — McMap. All rights reserved.