| 1. |
Solve : If statements in command line? |
|
Answer» Hi, from %%G after the query executes. That does not set the value; it echoes %BATCH_QUERY%, a colon, and WHATEVER %%G happens to be. If you did not do SET BATCH_QUERY= before, it will be undefined (blank). So,should it be like this...... set BATCH_QUERY=0 set BATCH_QUERY=for /F %%G in ('sqlcmd -E -S test-SQ17CL\SQL1A -d SalesInterface -h-1 -W -Q "set nocount on;SELECT count(*) FROM table_test"') do echo %%G Quote from: priyabala on September 20, 2010, 02:58:22 PM So,should it be like this...... If you want the output of the sqlcmd command to be assigned to the variable BATCH_QUERY you could do something like this Code: [Select]for /F %%G in ('sqlcmd -E -S test-SQ17CL\SQL1A -d SalesInterface -h-1 -W -Q "set nocount on;SELECT count(*) FROM table_test"') do set BATCH_QUERY=%%G is it going to be a number? Sorry about the delayed reply. Yes, it is going to be a number. Also,can you please let me know how to do multiple conditions in if statments.Is this correct. if %ERRORLEVEL% equ 0 if %BATCH_QUERY% gtr 0 (GOTO LASTSTEP) if %ERRORLEVEL% NEQ 0 (GOTO ERROR1) Please let me know.I really appreciate your help on this. Thanks. Code: [Select] REM put this test FIRST if %errorlevel% neq 0 goto error1 REM You will only get here if errorlevel is 0 if %batch_query% gtr 0 goto laststep REM If you get here errorlevel is 0 and batch_query is 0 REM What are you going to do? REM Maybe goto end? REM If you do nothing you will go to the next line. REM Which is laststep... :laststep REM Your code goto end :error1 REM your code :end Also... in your code... Code: [Select]echo %JOBNAME% Abended REM THERE WAS AN ERROR! SET CONTROLM=1 goto END :END 1. The goto END statement is superfluous, because you are going there anyway. 2. "Abended" is not an ENGLISH word. Thanks for all your replies.I'll try these.I have always found life easier if a script commences ECHO OFF or even ECHO OFF I rather doubt that there is any benefit from starting with ECHO ON Alan |
|