title: Error Handling in .bat File
body: <p>I have a .bat file which runs two SQL files and moves files around. I need to have some error handling in this .bat file. I want it to take the error generated in sql and pass it into AutoSys
  I was provided with this code: </p>
  
  <pre><code>#!/bin/sh 
  . $HOME/.bash_profile
  
  sqlplus -s $AUTOSYS_DB_USER/$AUTOSYS_DB_PASSWD &lt;&lt;!
  WHENEVER OSERROR EXIT 999;
  WHENEVER SQLERROR EXIT SQL.SQLCODE;
  alter session set nls_date_format='DD/MM/YYYY';
  execute P_LOST_APPROVALS;
  !
  
  exit_code=$?
  if [ $exit_code != 0 ]; then
  echo "Error calling sqlplus, return code = " $exit_code
  exit $exit_code
  fi
  
  exit 0
  </code></pre>
  
  <p>However, I need it to run in .bat file and not Linux?</p>
  
  <p>I currently have: </p>
  
  <pre><code>echo exit | sqlplus -s %CONNECT% @Code.sql 
  IF %ERRORLEVEL% NEQ 0 (
  echo Unsuccessful
  goto @ERROR_HANDLING_SQL
  )
  </code></pre>
  
  <p>Full .bat file:</p>
  
  <pre><code>@echo off
  call config.bat
  SET CONNECT=%var1%/%var2%@avpr.world
  
  Pushd  Location
  
  
  Set SCRIPTPATH=Location
  Set RESULTPATH=Location
  
  
  echo exit | sqlplus -s %CONNECT% @Code.sql
  IF %ERRORLEVEL% NEQ 0 (
  echo Unsuccessful
  goto @ERROR_HANDLING_SQL
  )
  
  
  echo exit | sqlplus -s %CONNECT% @createTXT.sql &gt; File%date:~0,2%%date:~3,2%%date:~6,4%.txt
  IF %ERRORLEVEL% NEQ 0 (
  echo Unsuccessful
  goto @ERROR_HANDLING_SQL
   )
  
  
  
  move "File%date:~0,2%%date:~3,2%%date:~6,4%.txt" %RESULTPATH%
  
  
  echo exit | sqlplus -s %CONNECT% @dropTable.sql
  IF %ERRORLEVEL% NEQ 0 (
  echo Unsuccessful
  goto @ERROR_HANDLING_SQL
  )
  
  
  
   : ERROR_HANDLING_SQL
   &lt;echo -1&gt;
  
  pause
  Exit
  </code></pre>