我们目前有一个调度程序来运行审计。这个调度器会调用一个带参数的批处理文件,批处理文件调用一个sql脚本(基于参数),然后调用一个存储的proc。
对于每个运行的审计,一个单独的批处理文件和 sql 文件。最好的情况是我想将以下两个文件合并为一个可用于每次新审计的文件。在最坏的情况下,我至少希望为每次审计合并获取 1 个文件,而不是两个。希望大家能帮忙?
批处理文件
@echo on
Echo Running SQL Command File for '%1' Data Audit Check
del "D:\Internal_Reports\%1\%1.txt"
sqlcmd -S localhost -d database -i "D:\DataAudit\%1.sql" -s "," > D:\Temp\%1.csv -I -W -k 1
if %ERRORLEVEL% GTR 0 COPY "D:\Temp\%1.csv" "D:\Internal_Reports\%1\%1.txt"
if %ERRORLEVEL% NEQ 0 goto Error_1
echo No Errors
goto end
:Error_1
if %ERRORLEVEL% NEQ 1 goto Error_2
echo No Errors
goto end
:Error_2
echo Errorlevel %ERRORLEVEL%
set FileName=%1%2
echo Filename %FileName%
echo %ERRORLEVEL% > D:\ErrorLevel\%FileName%
EXIT /B %ERRORLEVEL%
:end
SQL 文件
set NoCount on
DECLARE
@createdBy varchar(16),
@dataAuditBatchId int,
@createdDtTm datetime
select
@createdBy = 'AutomatedAudit'
exec CreateNewDataAuditBatch @createdBy, @dataAuditBatchId output
-- Content Scripts
exec specificAuditStoredProc @createdBy, @dataAuditBatchId
select * from vAuditErrors where JobName in ('specificAuditStoredProc')
:exit(select Case When Counter = 0 then 0 Else 1 End 'errorCode'
from (select CAST(Count(*) AS varchar(4)) AS Counter from vAuditErrors
where JobName in ('specificAuditStoredProc'))
CountTable
)