0

(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)
2

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.

3
  • Thanks. I already used SET NOCOUNT ON, but was hoping for a SET command to do what unchecking Include column headers in the result set does.
    – RonJohn
    Jun 15 '20 at 14:05
  • 2
    I don't think there is a set option that would do such a thing. You could use a "UNION" to get rid of the "---" that is between both result set but you will still have the first one. Using a tool like Powershell could easilly remove those line as well if are using this for some kind of automation. Jun 15 '20 at 14:33
  • 1
    @RonJohn the control switch for that is a client-side control used solely for display, unlike SET NOCOUNT ON; which is a TSQL server-side command which affects what the server sends to the client
    – AMtwo
    Jun 15 '20 at 21:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.