Share via


How to suppress header and feedback in the query output?

Question

Tuesday, October 16, 2007 9:59 AM

I am using Sql Server 2005.

 

G:\Data\Misc_scripts>sqlcmd -S localhost -U cust -P cust -Q "Exit(select distinct eventid from location_stage where batchid='20070917_BEN_10')" -o"Oo_EventId.txt"

G:\Data\Misc_scripts>type oo_eventid.txt
eventid

20071012094456

(1 rows affected)

 

In the above you could see that the sqlcmd utility runs a query and the output goes to a file.

 

How do I suppress the column name header and the "(1 rows affected)" feedback in the query output?

 

Thanks.

All replies (7)

Tuesday, October 16, 2007 11:36 AM ✅Answered

 

And as Kent said use the -h-1 option. From Books Online:

 

-h headers

Specifies the number of rows to print between the column headings. The default is to print headings one time for each set of query results. This option sets the sqlcmd scripting variable SQLCMDHEADERS. Use -1 to specify that headers must not be printed. Any value that is not valid causes sqlcmd to generate an error message and then exit.

 

For more information, please refer http://msdn2.microsoft.com/en-us/library/ms162773.aspx


Tuesday, October 16, 2007 11:30 AM | 1 vote

Maybe try adding the "-h" tag; something like:

 

sqlcmd -S localhost -U cust -P cust -Q "Exit(select distinct eventid from location_stage where batchid='20070917_BEN_10')" -o"Oo_EventId.txt -h-1


Tuesday, October 16, 2007 11:31 AM | 1 vote

Hi,

 

The "1 row affected" message can be disabled using the following before executing a query

 

Code Block

SET NOCOUNT ON

 

 

 

For more information, please refer http://msdn2.microsoft.com/en-us/library/ms189837.aspx

 

HTH


Tuesday, October 16, 2007 1:44 PM

Thanks a lot Kent and Amit.

 


Friday, December 28, 2007 9:06 PM

Is it possible to supress the dashes () that appear just below the column names in the header?

 


Friday, March 27, 2009 1:25 AM

I am having the same issue.
I want headers, but I do not want the dashes


Thursday, September 1, 2011 2:18 AM

Found a solution to suppressing the dashes:

sqlcmd <parameters that allow default headers> -o Temp.txt
type  Temp.txt | findstr /v \\ > DestFile.txt
del Temp.txt

Caveat: Since this suppresses output of any lines with more than one consecutive dash, your data cannot contain "--".