How to check for SQL condition in batch file?

Microsoft Microsoft windows xp pro full...
January 20, 2010 at 07:59:05
Specs: Windows XP, 2.4 3GB
How do I perform the following logic in a batch file?
Check for SQL condition (if temp table exists)
-If table doesn't exist, execute notrunning.bat

See More: How to check for SQL condition in batch file?

Report •

January 20, 2010 at 12:44:46
Well.. it's taken me all day because I'm not a batch file writer.. but with the help of my good friend Google, I've managed to do it. I'll share the results in case anyone else ever has the question..

The batch file runs a local sql statement on a remote database, looking for a temp table that I am having created when I launch an .exe on my local box. If it finds that temp table.. program exits and all is well. If it doesn't see it, it shoots me an email via blat (I put my 3 blat files in C:\Windows). Most of you probably know what blat is, but if not.. it's a command line email program. Additionally, the server I was on didn't have smtp, so I installed QK SMTP server.. a little portable mail server I can setup just for this.

If you have any suggestions for my batch file, feel free to offer. I don't do much in this. In fact, I had EXIT in my code and couldn't figure out for the longest time that EXIT makes it retain the last %errorlevel% value, so my query was always returning a 0 (true). Putting END in seemed to resolve this for me. It was driving me mad for a good hour.

I then setup a Scheduled Task in Windows to run my batch file every 15 minutes all day, every day.
Anyway.. here's my code. Cheers!

@echo off

osql -SJeffsServer -dmaster -Usa -Psecretpw -iC:\Jeff\BatchFiles\mysqlscript.sql -n -b > optionallogfilewithSQLresults.txt

echo %errorlevel%

Echo %date% %time% not running at this time. >> C:\Jeff\BatchFiles\ProgramDownTimeLog.txt
c:\windows\blat.exe - -to "," -f "This email is from..." -s "Subject of Email" -ti 30 -try 120 -noh -body "Your program quit running" -attach "C:\Jeff\BatchFiles\ProgramDownTimeLog.txt" -server ---- ( was just my server name after installing my smtp program)




Report •
Related Solutions

Ask Question