How to suppress hyphens in SQLCMD

I didn’t see all this info in once place and thought the next person looking for it might appreciate it…

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.

Example:

SQLCMD -S 127.0.0.1\SQL_SERVER_Instance -d db_name -U db_login -P password -i your_script.sql -o your_output.csv -h -1

In your SQL script:

SET NOCOUNT ON -- removes (rows affected from the output)
select 'your_column_1, your_column_2'
select * from your_table

You don’t need to use a union between your select statements for this.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)