Computing.Net > Forums > Programming > Help with loop

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Help with loop

Reply to Message Icon

Name: JackInDaBox
Date: May 16, 2007 at 07:59:36 Pacific
OS: XP Pro
CPU/Ram: FX 64 \ 2GB RAM
Product: Home made
Comment:

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 :process
goto :eof

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

Thanks



Sponsored Link
Ads by Google

Response Number 1
Name: IVO
Date: May 16, 2007 at 12:38:08 Pacific
Reply:

@Echo Off

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

For %%a in (*.sql) do (
osql -E -S %ServerName% -d %DatabaseName% -n -i %%a >> Report.txt)


0
Reply to Message Icon

Related Posts

See More


How to know what procces ... .bat to .exe



Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: Help with loop

Help with a C Program / Newbie www.computing.net/answers/programming/help-with-a-c-program-newbie/8071.html

Help with loops www.computing.net/answers/programming/help-with-loops/20083.html

Help with debugging C++ code www.computing.net/answers/programming/help-with-debugging-c-code/13083.html