使用以下sqlcmd脚本:
sqlcmd -S . -d MyDb -E -s,-W -Q "select account,rptmonth,thename from theTable" > c:\dataExport.csv
acctnum,facilname
——-,——–,———
ALLE04,201406,Allendale Community for Senior Living-LTC APPL02,Applewood Estates
ARBO02,Arbors Care Center
ARIS01,AristaCare at Cherry
Hill
. . .(139 rows affected)
我尝试使用parm -h-1,但是除了列标题和虚线.
解决方法
解决方案:
1)要删除行计数(“(139行受影响)”),您应该使用SET NOCOUNT ON语句.见ref.
2)要删除列标题,应使用值为-1的-h参数.见ref (section Formatting Options).
例子:
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.
要么
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"