Sql 如何对批处理文件的输入进行排序
我正在使用以下脚本执行一组.sql语句Sql 如何对批处理文件的输入进行排序,sql,batch-file,sqlcmd,Sql,Batch File,Sqlcmd,我正在使用以下脚本执行一组.sql语句 @echo off ECHO %USERNAME% started the batch process at %TIME% >output.txt for %%s in (*.sql) do ( sqlcmd.exe -S.\ -E -i "%%s" >>output.txt ) pause 但是,我想确保文件已排序(名称),因为我不能保证列表是有序的。您可以使用此选项按名称顺序循环它们 for /f %%s in ('
@echo off
ECHO %USERNAME% started the batch process at %TIME% >output.txt
for %%s in (*.sql) do (
sqlcmd.exe -S.\ -E -i "%%s" >>output.txt
)
pause
但是,我想确保文件已排序(名称),因为我不能保证列表是有序的。您可以使用此选项按名称顺序循环它们
for /f %%s in ('dir *.sql /b /o:n') do (
sqlcmd.exe -S.\ -E -i "%%s" >>output.txt
)
pause
无需担心,按名称对文件进行排序(处理),但如果需要其他方式,也可以对输出文件进行排序:
@echo off
ECHO %USERNAME% started the batch process at %TIME% >output.txt
FOR %%s in ("*.sql") do (sqlcmd.exe -S.\ -E -i "%%s" >> "%TEMP%\output.txt")
TYPE "%TEMP%\output.txt" | SORT > ".\Final_Output.txt"
Pause&Exit