Question about sqlcmd

  • I am using the follwoing construct to output a query result to a pipe delimited test file:

    sqlcmd -E -SSERVERNAME -itestquery.txt -otestfile.txt -h-1 -W -s"|"

    Everything looks good except that I am getting messages like these in the file:

    Changed database context to 'ISIS'.

    (1 rows affected)

    How do I redirect or supress them?

  • I never really use sqlcmd, but maybe if you set nocount on in your statement, you will suppress the record counts - seems to work that way in SSMS

  • I haven't used SQLCMD but i got this from BOL.

    "h headers

    Specifies the number of rows to print between the column headings. The default is to print headings one time for each set of query results. This option sets the sqlcmd scripting variable SQLCMDHEADERS. Use -1 to specify that headers must not be printed. Any value that is not valid causes sqlcmd to generate an error message and then exit.

    "

    Check out BOL for more on this.

    "Keep Trying"

  • I figured it out.

    Adding the "-m1" parameter to the sqlcmd command suppressed the "Changed database context" message.

    Adding SET NOCOUNT ON to the query suppressed the "(1 rows affected)" message.

    NOTE: As I said, I am using sqlcmd to write the results of a query to a text file for interfacing to another system. If anyone can shed light on a better method, I would like to hear about it.

Viewing 4 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic. Login to reply