# Help with Batch file loop (win xp)



## JackInDaBox (May 16, 2007)

Hello,
I am trying to run all SQL scripts (with no params) in the same folder as the batch file is. I have not done much with batch files before but I think I have gotten close. It seems to work if I hard code the FILENAME.sql but will of course only work for the file I hard coded. What I need is to get the present file name from the loop and put it in to the FILENAME.sql so it will run that sql script. Hope this makes some sense. Here is what I have so far:
@echo off 

SET ServerName= 
SET /P ServerName= Please enter the Server Name: 
SET DatabaseName= 
SET /P DatabaseName=Please Enter Database Name: 

for /f %%a in ('dir /b *.sql') do call rocess 
goto :eof

rocess
osql -E -S %ServerName% -d %DatabaseName% -n -i FILENAME.sql > Report.txt


Thanks


----------



## dtech10 (Jan 31, 2003)

This work OK

@echo off 
SET ServerName= 
SET /P ServerName= Please enter the Server Name: 
SET DatabaseName= 
SET /P DatabaseName=Please Enter Database Name: 

for /f %%a in ('dir /b *.sql') do call process %%a
goto :eof

process %1
osql -E -S %ServerName% -d %DatabaseName% -n -i %1 > Report.txt


----------

