How can I suppress hyphens (------------) from the results set of this sqlcmd
command:
C:\temp>sqlcmd -d AdventureWorks -s ";" -Q "SET NOCOUNT ON SELECT top 5 FirstName, LastName FROM Person.Contact;" FirstName ;LastName --------------------------------------------------;---------------------------- Gustavo ;Achong Catherine ;Abel Kim ;Abercrombie Humberto ;Acevedo Pilar ;Ackerman C:\temp>
No, the hyphen is an operator, and you can't use that in the middle of an identifier.
The double hyphen places a single-line comment in a SQL*Plus script. The double hyphen works the same way as REMARK, except that it may be used in SQL statements and PL/SQL blocks. When used in a SQL statement or PL/SQL block, the double hyphen may be used to add trailing comments to a line.
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 lets you enter Transact-SQL statements, system procedures, and script files through a variety of available modes: At the command prompt. In Query Editor in SQLCMD mode.
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.
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