sqlcmd options on print / display

helena Matos 61 Reputation points
2020-12-02T21:51:02.873+00:00

Hello

i need some help with sqlcmd utility at linux I have this select statement, but it display both at start with the -----

1> select 'grant select on ' + name + ' to READONLY' + CHAR(10) + 'go' from sysobjects where type = 'U' or type = 'V' or type = 'P'
2> go

------------------------------------------------------------------------------------------------------------------------------------

then a the end show the numbers

(34 rows affected)

how can the --- and the ( x rows affected) be ignored?
is there away in the sqlcmd to pass some parameter to ignore the lines?
thank you

SQL Server
SQL Server
A family of Microsoft relational database management and analysis systems for e-commerce, line-of-business, and data warehousing solutions.
9,116 questions
No comments
{count} votes

1 additional answer

Sort by: Most helpful
  1. AmeliaGu-MSFT 13,891 Reputation points Microsoft Vendor
    2020-12-03T02:41:20.403+00:00

    Hi @helena Matos ,
    As Erland mentioned, to remove dashed line header, you can use -h parameter with value -1, and to remove row count, you should use “SET NOCOUNT ON” in query.
    For example:

    sqlcmd -S wx-80490 -h -1  
    1> set nocount on; select 'grant select on ' + name + ' to READONLY' + CHAR(10) + 'go' from sysobjects where type = 'U' or type = 'V' or type = 'P'  
    2>go  
    

    And

    sqlcmd -S . -h -1 -Q "set nocount on; select 'grant select on ' + name + ' to READONLY' + CHAR(10) + 'go' from sysobjects where type = 'U' or type = 'V' or type = 'P'"  
    

    Please refer to the sqlcmd syntax for more details.

    Best Regards,
    Amelia


    If the answer is helpful, please click "Accept Answer" and upvote it.
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.