Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

sqlcmd output file remove header and footer

Using SQLCMD, I can output the query result to a text file, now, the text file has header: enter image description here

And footer: enter image description here

How do I remove them during query?

My query, inside a sql file:

SELECT internal_no, item_no, dspl_descr, rtl_prc FROM PLU

My SQLCMD command:

SQLCMD -S SQLSERVER01 -U AdminUser -P au5584 -i C:\text.sql -o C:\out.txt

like image 477
jaa2013 Avatar asked Apr 08 '15 07:04

jaa2013


People also ask

How do I remove a header in SQL?

When you use the sp_send_dbmail stored procedure to email the results of a query, the column headers are included by default. You can include or exclude the column headers with the @query_result_header argument. To remove the column headers, use @query_result_header = 0 .

How do I turn off hyphens in Sqlcmd?

use the -h -1 option to remove the dashes (--------) from the output and SET NOCOUNT ON to remove the "rows affected". This is great if you're creating a report or CSV file for another system to process.

How do I use Sqlcmd mode?

To switch a Database Engine Query Editor window to SQLCMD mode. In Object Explorer, right-click the server, and then click New Query, to open a new Database Engine Query Editor window. On the Query menu, click SQLCMD Mode. The Query Editor executes sqlcmd statements in the context of the Query Editor.

What is Sqlcmd command?

The sqlcmd utility is a command-line utility for ad hoc, interactive execution of Transact-SQL statements and scripts and for automating Transact-SQL scripting tasks. To use sqlcmd interactively, or to build script files to be run using sqlcmd, users must understand Transact-SQL.


1 Answers

Add

SET NOCOUNT ON

To the top of your query

SET NOCOUNT ON    
SELECT internal_no, item_no, dspl_descr, rtl_prc FROM PLU

And add "-h-1" your SQLCMD command to:

SQLCMD -h-1 -S SQLSERVER01 -U AdminUser -P au5584 -i C:\text.sql -o C:\out.txt
like image 200
Dbloch Avatar answered Sep 21 '22 04:09

Dbloch