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

后端 未结 8 1781
难免孤独
难免孤独 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:36

    To remove the Row Count: Add the below to your SQL statement

        SET NOCOUNT ON;
    

    To remove the hyphen row try the following upon successful execution:

        findstr /v /c:"---" c:\dataExport.csv > c:\finalExport.csv
    

    I use "---" as all my columns are over 3 characters and I never have that string in my data but you could also use "-,-" to reduce the risk further or any delimiter based on your data in place of the ",".

提交回复
热议问题