1

我有以下命令:

sqlcmd -S CHLWBIDB204 -d PayrollReports -U finance_lookup -P lawson -i"L:\Lawson\EEIMPORT.sql" -W -o "Z:\EmployeeImport.csv" -h-1 -s"," 

它工作得很好,除了这个文件的接收者不能用空行接受它和它提供的总数。

就像是:

           ...
(line 10)  1, 2292, KPR, 7.94
(line 11)
(line 12)  (10 rows affected)

第 11 行和第 12 行不能在文件中,所以我认为需要一些命令才能在空行处停止。

4

2 回答 2

1

All you need to do is pipe the output to FINDSTR and filter out the unwanted lines.

The /V option throws away lines that match. The command below looks for empty lines and your count line. The search terms may have to be refined - I don't have sqlcmd to test with.

sqlcmd .... | findstr /v /c:"^$" /c:"([0-9]* rows affected)"

Instead of searching for lines to throw away, you may be able to search for lines to keep. As long as the desired output always has at least 2 comma delimited columns, then you can simply search for any line that contains a comma.

sqlcmd .... | find ","
于 2013-02-21T04:10:32.453 回答
0

如果您可以编辑该.sql文件,SET NOCOUNT ON;请在 SELECT 语句之前添加。(或者,以不同的名称保存脚本的修改版本并使用它。)

这将抑制… rows affected消息(连同前面的空行)。

于 2013-02-21T14:50:09.507 回答