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

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

    The guy with the top answer didn't answer how to remove the dashed line. This is my awesome solution.

    1. First include -h -1 which removes both the dashed line and header
    2. Then before your select statement manually inject the header string that you need with a PRINT statement. So in your case PRINT 'acctnum,rptmonth,facilname' select..*...from...

    Sorry I'm 4 years and 9 months late.

提交回复
热议问题