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

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

    Use the following;

    sqlcmd -S . -d MyDb -E -s, -h-1 -W -Q "set nocount on;select 'account','rptmonth', 'thename';select account,rptmonth, thename from theTable"  
    > c:\dataExport.csv
    
    • remove the header -h-1
    • remove row count [set nocount on;]
    • add header select [select 'account','rptmonth', 'thename';]
    • add your select [select account,rptmonth, thename from theTable;]

提交回复
热议问题