是否可以保留 headers 但使用 sqlcmd 删除 sql 输出的连字符
Is it possible to keep the headers but remove the hyphens of a sql output using sqlcmd
Objective:
在使用
通过 sqlcmd 执行 sql 查询时,我能够删除连字符
|findstr /v /c:"---"
然而,问题是我不能将上面的代码与我的“-o”变量这样组合:
sqlcmd -S INSTANCENAME -s ";" -Q "SET NOCOUNT ON; SELECT top 5 * FROM table" |findstr /v /c:"---" -o output.csv
错误信息:
FINDSTR: Cannot open output.csv
注意:我需要保留我的 headers。
嗯,findstr
command does not feature an option -o
to create an output file. However, you can use output redirection把结果写入文件,像这样:
sqlcmd -S INSTANCENAME -s ";" -Q "SET NOCOUNT ON; SELECT top 5 * FROM table" | findstr /V /C:"---" > "output.csv"
请注意,如果文件 output.csv
已经存在,恕不另行通知,这将覆盖该文件。要附加到输出文件而不是覆盖它,只需将 >
替换为 >>
。
Objective:
在使用
通过 sqlcmd 执行 sql 查询时,我能够删除连字符|findstr /v /c:"---"
然而,问题是我不能将上面的代码与我的“-o”变量这样组合:
sqlcmd -S INSTANCENAME -s ";" -Q "SET NOCOUNT ON; SELECT top 5 * FROM table" |findstr /v /c:"---" -o output.csv
错误信息:
FINDSTR: Cannot open output.csv
注意:我需要保留我的 headers。
嗯,findstr
command does not feature an option -o
to create an output file. However, you can use output redirection把结果写入文件,像这样:
sqlcmd -S INSTANCENAME -s ";" -Q "SET NOCOUNT ON; SELECT top 5 * FROM table" | findstr /V /C:"---" > "output.csv"
请注意,如果文件 output.csv
已经存在,恕不另行通知,这将覆盖该文件。要附加到输出文件而不是覆盖它,只需将 >
替换为 >>
。