Sqlcmd to generate file without dashed line under header, without row count

后端 未结 8 1756
难免孤独
难免孤独 2021-02-01 06:09

Using the following sqlcmd script:

sqlcmd -S . -d MyDb -E -s, -W -Q \"select account,rptmonth, thename from theTable\"  
> c:\\dataExport.csv
<
8条回答
  •  一向
    一向 (楼主)
    2021-02-01 06:55

    Solutions:

    1) To remove the row count ("(139 rows affected)") you should use SET NOCOUNT ON statement. See ref.

    2) To remove column headers you should use -h parameter with value -1. See ref (section Formatting Options).

    Examples:

    C:\Users\sqlservr.exe>sqlcmd -S(local)\SQL2012 -d Test -E -h -1 -s, -W -Q "set nocount on; select * from dbo.Account" > d:\export.txt. 
    

    or

    C:\Users\sqlservr.exe>sqlcmd -S(local)\SQL2012 -d Test -E -h -1 -s, -W -Q "set nocount on; select * from dbo.Account" -o "d:\export2.txt"
    

提交回复
热议问题