我有一个非常简单的问题(这些问题通常是我大部分时间都在扯头发的问题)。我正在使用批处理文件来执行与批处理位于同一目录中的所有 .sql 查询,并将其所有结果保存到各种 .csv 文件中。
这是我的代码:
@echo off
REM Check that all parameters are present
@IF "%1"=="" goto error
@IF "%2"=="" goto error
@IF "%3"=="" goto error
@IF "%4"=="" goto error
REM For every *.sql file in this folder "." and all its subfolders (/R), do the following:
@for /R "." %%F in (*.sql) do (
REM Print the command to be executed:
@echo Database : @SqlCmd -S %1 -U %2 -P %3 -d %4 -I -l60 -i "%%F" -o "%%F.output.csv" -h-1 -s"," -w 1000 -W
REM Execute the command:
@SqlCmd -S %1 -U %2 -P %3 -d %4 -I -l60 -i "%%F" -o "%%F.output.csv" -h-1 -s"," -w 1000 -W
)
goto :EOF
:error
@echo Incorrect syntax :
@echo extract.cmd [servername] [user id] [password] [databasename]
@echo
@pause
goto :EOF
作为测试,我运行以下查询:
select top(10) [name] from sysobjects
输出:
sysrscols
sysrowsets
sysallocunits
sysfiles1
syspriorities
sysfgfrag
sysphfg
sysprufiles
sysftinds
sysowners
(10 rows affected)
这工作正常,除了两件事。首先,我还需要输出列标题。所以我删除了“-h -1”参数,然后给出:
name
----
sysrscols
sysrowsets
sysallocunits
sysfiles1
syspriorities
sysfgfrag
sysphfg
sysprufiles
sysftinds
sysowners
(10 rows affected)
这很好,除了我不希望标题和第一行数据之间的水平规则“------”。
另外,我不希望输出“(受影响的 10 行)”行。
有人知道我怎么能做到这一点吗?
谢谢卡尔
_