5

My Script

echo "Enter your choice (1 or 2 or 3) :"
set /p dbchoice=

IF %dbchoice EQU 1 ( 
    set dbtype="oracle"
) ELSE ( 
    IF %dbchoice EQU 2 ( 
        set dbtype="sqlserver" 
    )
) ELSE ( 
    IF %dbchoice EQU 3 ( 
        set dbtype="db2" 
    )
) ELSE (
    echo "Incorrect choice" 
)

I get the following output:

E:\csmilm>set /p dbchoice=
1
ELSE was unexpected at this time.
E:\csmilm>) ELSE (
E:\csmilm>

What is the problem here?

2
  • On which line does the error occur? Commented Oct 10, 2011 at 9:12
  • @tenfour: Check my partial output/ rather error Commented Oct 10, 2011 at 9:13

1 Answer 1

11

Closing brackets in the wrong place. Try:

IF %dbchoice EQU 1 ( 
    set dbtype="oracle"
) ELSE ( 
    IF %dbchoice EQU 2 ( 
        set dbtype="sqlserver" 
    ) ELSE ( 
        IF %dbchoice EQU 3 ( 
            set dbtype="db2" 
        ) ELSE (
            echo "Incorrect choice" 
        )
    )
)
Sign up to request clarification or add additional context in comments.

5 Comments

It gives me E:\csmilm>set /p dbchoice= 1 E:\csmilm>IF dbchoice EQU 1 (set dbtype="oracle" ) ELSE (IF dbchoice EQU 2 (set dbtype="sqlserver" ) ELSE (IF dbchoice EQU 3 (set dbtype="db2" ) ELSE ( echo "Incorrect choice" goto end_java_version ) ) ) "Incorrect choice" E:\csmilm>endlocal
windows batch file does not know anything about integers. try if %dbchoice equ "1"
Still does not work I added IF %dbchoice EQU "1" and even IF %dbchoice == "1"
@Adrien and ChrisBD: Also 1 more help, what if I want to check if something is >= 5 how can I do that in batch script?
you type help if on a command-line and read the documentation. what you need is to replace EQU by GEQ.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.