Looping sqlcmd until condition is met
Posted: 05 Oct 2021 15:01
Am trying to loop through the below code until the count returns value greater than 0 (Each iteration should get paused for 5 minutes).
Once count returns value greater than 0 it has to exit the indefinite loop and fire insert query to specific table.
Am connecting to sql server DB
for /f %%a in ('sqlcmd -S <SERVER> -d <DATABASE> -Q "SET NOCOUNT ON; select max(dt) as dt from prm"') do set var_dt=%%a
for /f %%a in ('sqlcmd -S <SERVER> -d <DATABASE> -Q "SET NOCOUNT ON; select count(*) as cnt from Table2 where dt=cast('%var_dt%' as datetime)"') do pause 5 set var_cnt=%%a
Once count returns value greater than 0 it has to exit the indefinite loop and fire insert query to specific table.
Am connecting to sql server DB
for /f %%a in ('sqlcmd -S <SERVER> -d <DATABASE> -Q "SET NOCOUNT ON; select max(dt) as dt from prm"') do set var_dt=%%a
for /f %%a in ('sqlcmd -S <SERVER> -d <DATABASE> -Q "SET NOCOUNT ON; select count(*) as cnt from Table2 where dt=cast('%var_dt%' as datetime)"') do pause 5 set var_cnt=%%a