title: Getting error "The rollback transaction request has no corresponding begin transaction"
body: <p>I am trying to create a trigger and for some reason the second if statement breaks my code.</p>
  
  <p>If I delete the second if statement the code will work. The error that I am getting is:</p>
  
  <blockquote>
    <p>The rollback transaction request has no corresponding begin transaction</p>
  </blockquote>
  
  <p>My code:</p>
  
  <pre><code>create trigger insertemployee 
  on jobinsailing 
  after insert 
  as 
  
  BEGIN TRANSACTION   
  
  declare @sailingID        int, 
          @employeeID       char(9), 
          @jobTitle         varchar(10), 
          @sailingStartDate date, 
          @sailingEndDate   date 
  
  select @sailingId = inserted.sailingid, 
         @employeeID = inserted.employeeid, 
         @jobTitle = inserted.jobtitle, 
         @sailingStartDate = sailing.leavingtime, 
         @sailingEndDate = sailing.returntime 
  from   inserted 
         inner join sailing 
                 on inserted.sailingid = sailing.sailingid 
  
  if exists(select employeeid 
            from   sailing 
                   inner join jobinsailing 
                           on sailing.sailingid = jobinsailing.sailingid 
            where  ( @sailingStartDate &lt;= returntime ) 
                   and ( leavingtime &lt;= @sailingEndDate ) 
                   and employeeid = @employeeID) rollback TRANSACTION; 
  
  
  else if exists((select sailing.sailingid 
            from   sailing 
                   inner join jobinsailing 
                           on jobinsailing.sailingid = sailing.sailingid 
            where  Datediff(day, @sailingStartDate, sailing.leavingtime) &lt;= 4 
                    or Datediff(day, @sailingEndDate,sailing.leavingtime) &lt;= 4 
                    or Datediff(day, @sailingStartDate,sailing.returntime) &lt;= 4 
                    or Datediff(day, @sailingEndDate,sailing.returntime) &lt;= 4
                    ))  rollback TRANSACTION;
  
  COMMIT TRANSACTION
  </code></pre>