Using SQLCMD
, I can output the query result to a text file, now, the text file has header:
And footer:
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
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 .
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.
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.
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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With