I have a batch job that runs every week to calculate money spent by employees in a week.
WriteToDBIndex
is a C# program that checks other process like if finance have finished processing data (i.e. entered all employees spending data). If yes, WriteToDBIndex
, writes a row in emptablestat
table with JobStatusName
& status
if all data is entered.
I need to keep checking this until count for FINANCE & empstatus=1
is one. I have timeout set for 3600 seconds.
@ECHO OFF
set ERRORLEVEL=0
REM start "" "C:\WriteToDBIndex.exe"
:gobackloop
set ct=0
if %ERRORLEVEL% NEQ 0 (
Echo There has been an error.
goto end
)
if %ERRORLEVEL% EQU 0 (
Echo inside errorlevel zero
for /F "usebackq" %%i in (`sqlcmd -E -S "MYDATA\MYDB" -h-1 -Q "SELECT COUNT(*) FROM [dbo].[emptablestat] where JobStatusName like '%FINANCE%' and empstatus=1"`) do set ct=%%i
if %ct% EQU 1 (
echo starting 1
start "" "C:\CalculateMoneySpent.exe"
timeout /t 60
)
if %ct% EQU 0 (
timeout /t 3600
goto :gobackloop
)
)
:end
echo END
REM cd ..
The value of variable ct is somehow always zero even after I have the count of one in emptablestat
table. I am not sure why.
Thanks R