0

I have the script below which is performing correctly, but basically I want the .bat to ask the user if they want a list of casinos before entering the casino name and username, then, if they select l (lower-case letter EL) for list, it produces the list of casinos. Currently getting 'error converting exit value'. Can anyone tell me the code for this?

@echo off
osql -STEMP7 -E -dAAMS888 -w256 -qEXIT("SET NOCOUNT ON SELECT casino_desc from casino") -b

set /p var1= Enter Casino Name : 
set /p var2= Enter Screen name : 

osql -STEMP7 -E -dAAMS888 -w256 -QEXIT("DECLARE @r int EXEC @r = usp_AddToObservationtbl '%var1%','%var2%' SELECT @r") -b -oc:\bat\observation.log
exit errorlevel
Andriy M
  • 71,352
  • 17
  • 87
  • 142
Chris Wood
  • 498
  • 9
  • 27

1 Answers1

1

The exit value converting error is fixed by changing the line

exit errorlevel

to

exit %errorlevel%

You want to return the value of the ERRORLEVEL variable, so you need to enclose the name in %s.

As for you first question, about asking the user to confirm whether they want to display the list of casinos, you could try something like this modification of your original script (added lines are highlighted in bold):

@ECHO OFF

SET /P "NeedsList= Do you want to display the list? "

IF /I NOT [%NeedsList%] == [L] GOTO :cont
osql -STEMP7 -E -dAAMS888 -w256 -qEXIT("SET NOCOUNT ON SELECT casino_desc from casino") -b

:cont
set /p var1= Enter Casino Name : 
set /p var2= Enter Screen name : 

osql -STEMP7 -E -dAAMS888 -w256 -QEXIT("DECLARE @r int EXEC @r = usp_AddToObservationtbl '%var1%','%var2%' SELECT @r") -b -oc:\bat\observation.log
exit %errorlevel%
Andriy M
  • 71,352
  • 17
  • 87
  • 142
  • I have fixed it using by removing some of the parameters @echo off SET /P "NeedsList= Do you want to display a casino list? (press l for list or any other key)" IF /I NOT [%NeedsList%] == [L] GOTO :cont osql -STEMP7 -E -dAAMS888 -w256 -Q "SET NOCOUNT ON SELECT casino_desc from casino" -b :cont set /p var1= Enter Casino Name : set /p var2= Enter Screen name : osql -STEMP7 -E -dAAMS888 -w256 -Q "DECLARE @r int EXEC @r = usp_AddToObservationtbl '%var1%','%var2%' SELECT @r" -b -oc:\bat\observation.log exit %errorlevel% – Chris Wood Jul 13 '11 at 15:22
  • sorry not allowed to answer my own question yet so couldn't edit this properly :( – Chris Wood Jul 13 '11 at 15:37
  • I can see that you made some modifications, but it seems to me like the parts that I specifically addressed in my answer remained basically untouched in your final script. If that is indeed so, you might consider [accepting](http://meta.stackexchange.com/questions/5234/how-does-accepting-an-answer-work) this answer formally, and I would also recommend you to go back and review answers to your other questions so as to accept some of them that worked for you, if any. – Andriy M Jul 13 '11 at 16:05
  • Hi Andriy, Well I didn't want to accept the answer as it didn't actually work in my script, maybe I was doing something wrong, but I didn't think I should promote it if I was uncertain – Chris Wood Jul 21 '11 at 10:31