I have the need to run a .bat file to run a SQL command on demand, It needs to have an if
nested within a for
and the if
should repeat until true.
What I have:
@echo off
cd "%UserProfile%\Desktop\Scripting\"
FOR /f "delims=" %%a in ('type queue.txt') DO (
:loop
IF EXIST reset.sql (
goto loop
) ELSE (
::Create SQL command
echo USE dbname> reset.sql
echo EXEC dbo.sp_ResetSubscription @ClientName = '%%a'>> reset.sql
echo EXEC dbo.sp_RunClientSnapshot @ClientName = '%%a'>> reset.sql
sqlcmd -i "reset.sql"
if exist reset.sql del /f /q reset.sql
)
)
if exist queue.txt del /f /q queue.txt
This bombs out when it hits the loop, if I move :loop from where it is to within the if statement it works fine, however that isn't much use.
What I need it to do is to keep looping until reset.sql
does not exist but at the same time stay within the same iteration of the loop.