Sqlcmd生成文件头下不带虚线,不带行数 [英] Sqlcmd to generate file without dashed line under header, without row count

查看:23
本文介绍了Sqlcmd生成文件头下不带虚线,不带行数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用以下 sqlcmd 脚本:

Using the following sqlcmd script:

sqlcmd -S . -d MyDb -E -s, -W -Q "select account,rptmonth, thename from theTable"  
> c:\dataExport.csv

我得到一个包含

acctnum,rptmonth,facilname

acctnum,rptmonth,facilname

-------,--------,---------
ALLE04,201406,Allendale Community for Senior Living-LTC APPL02,201406,Applewood EstatesARBO02,201406,Arbors 护理中心
ARIS01,201406,AristaCare at Cherry山
...

-------,--------,---------
ALLE04,201406,Allendale Community for Senior Living-LTC APPL02,201406,Applewood Estates ARBO02,201406,Arbors Care Center
ARIS01,201406,AristaCare at Cherry Hill
. . .

(139 行受影响)

有没有办法去掉列标题下的虚线:-------,--------,但保留列标题?

Is there a way to get rid of the dashed line under the column headers : -------,--------, but keep the column headers?

还有一种摆脱底部用于行数的两行的方法吗?

and also a way to get rid of the two lines used for the row count on the bottom?

我尝试使用 parm -h-1 但这摆脱了列标题以及虚线.

I tries using parm -h-1 but that got rid of the column headers as well as the dashed line.

推荐答案

解决方案:

1) 要删除行数((139 行受影响)"),您应该使用 SET NOCOUNT ON 语句.请参阅参考.

1) To remove the row count ("(139 rows affected)") you should use SET NOCOUNT ON statement. See ref.

2) 要删除列标题,您应该使用值为 -1-h 参数.请参阅参考(格式选项部分).

2) To remove column headers you should use -h parameter with value -1. See 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"

这篇关于Sqlcmd生成文件头下不带虚线,不带行数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆