Remove/suppress dashes from “Results to Text” output in SSMS?

clip art of 
 a double-quote character

Question

(This is just a “reproducer”, not the real code, because that’s long and complicated.)

The output of

SET NOCOUNT ON
select @@SERVICENAME
select @@version

is:

—————————————————————————–
MSSQLSERVER

—————————————————————————–
Microsoft SQL Server 2014 (SP3-CU4) (KB4500181) – 12.0.6329.1 (X64)
Jul 20 2019 21:42:29
Copyright (c) Microsoft Corporation
Enterprise Edition: Core-based Licensing (64-bit) on Windows NT 6.3 <X64> (Build 9600: ) (Hypervisor)

How can I get output which looks like this:

MSSQLSERVER

Microsoft SQL Server 2014 (SP3-CU4) (KB4500181) – 12.0.6329.1 (X64)
Jul 20 2019 21:42:29
Copyright (c) Microsoft Corporation
Enterprise Edition: Core-based Licensing (64-bit) on Windows NT 6.3 <X64> (Build 9600: ) (Hypervisor)

asked 2020-06-15 by RonJohn


Answer

Those dashes are separators between the column headers and the results, since the columns in your example have no names, that isn’t immediately obvious. You can see that better here:

SET NOCOUNT ON;
SELECT ServerName = @@SERVICENAME;
SELECT VersionInfo = @@version;

To suppress the column headers:

  • Go to the Tools menu then select Options
  • Navigate to Query Results >> SQL Server >> Results to Text
  • Uncheck the box for Include column headers in the result set.

Note that this settings page also includes other settings that affect the results both for "Results to text" and "Results to file", including maximum data length per column (else SSMS will silently truncate), and whether results should be fixed width (the default) or delimited.

answered 2020-06-15 by Andy Mallon