Search code examples
sql-server-2008sqlcmd

sqlcmd output file remove header and footer


Using SQLCMD, I can output the query result to a text file, now, the text file has header: enter image description here

And footer: enter image description here

How do I remove them during query?

My query, inside a sql file:

SELECT internal_no, item_no, dspl_descr, rtl_prc FROM PLU

My SQLCMD command:

SQLCMD -S SQLSERVER01 -U AdminUser -P au5584 -i C:\text.sql -o C:\out.txt


Solution

  • Add

    SET NOCOUNT ON
    

    To the top of your query

    SET NOCOUNT ON    
    SELECT internal_no, item_no, dspl_descr, rtl_prc FROM PLU
    

    And add "-h-1" your SQLCMD command to:

    SQLCMD -h-1 -S SQLSERVER01 -U AdminUser -P au5584 -i C:\text.sql -o C:\out.txt