使用以下sqlcmd脚本:
sqlcmd -S . -d MyDb -E -s, -W -Q "select account,rptmonth, thename from theTable"
> c:\dataExport.csv
我得到一个包含的csv输出文件
acctnum,rptmonth,facilname
-------,--------,---------
ALLE04,201406,Allendale Community for Senior Living-LTC APPL02,201406,Applewood Estates ARBO02,201406,Arbors Care Center
ARIS01,201406,AristaCare at Cherry Hill
. . .(139 rows affected)
有没有一种方法可以消除列标题下的虚线:-------,--------,但保留列标题?
以及一种摆脱用于底部行数的两行的方法?
我尝试使用parm -h-1,但摆脱了列标题和虚线。
最佳答案
解决方案:
1)要删除行数(“(影响139行)”),应使用SET NOCOUNT ON
语句。参见ref。
2)要删除列标题,您应该使用值-h
的-1
参数。参见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"
关于sql-server-2005 - Sqlcmd生成的文件头下没有虚线,没有行数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24497970/