title: Incorrect syntax near the keyword 'ELSE'
body: <p>I got a problem with <code>else</code> function.</p>
  
  <p>Here is my code </p>
  
  <pre><code>IF (Not Exists(SELECT * FROM Log_DB.dbo._LogJobSYS WHERE KillerJobID=@JKillerID AND DeadJobID=@CharID)) 
      BEGIN
          INSERT Log_DB.dbo._LogJobSYS(KillerJobID,DeadJobID,DeathTime)
          VALUES (@JKillerID, @CharID, GETDATE())
          BEGIN
              BEGIN
                  IF (@JKillerJobType = 1) /*TRADER*/ 
                  BEGIN
                  IF (Not Exists(SELECT * FROM SRO_VT_SHARD_INIT.dbo._CharJobTradersys Where CharID=@JKillerID))
                  BEGIN
                  INSERT SRO_VT_SHARD_INIT.dbo._CharJobTradersys(CharID,TraderPoints,Kills,Deaths,LastKill,Date)
                  VALUES (@JKillerID, 1, 1, 0, @JDeadNick, GETDATE())
                  END
                  ELSE Begin
                  UPDATE SRO_VT_SHARD_INIT.dbo._CharJobTradersys SET TraderPoints = TraderPoints +1, Kills = Kills +1, LastKill = @JDeadNick, Date = GETDATE() WHERE CharID = @JKillerID
                  END
                  END
              END
              ELSE 
                  IF (@JKillerJobType = 2) /*THIEF*/ 
                  BEGIN
                  IF (Not Exists(SELECT * FROM SRO_VT_SHARD_INIT.dbo._CharJobThiefsys Where CharID=@JKillerID))
                  BEGIN
                  INSERT SRO_VT_SHARD_INIT.dbo._CharJobThiefsys(CharID,ThiefPoints,Kills,Deaths,LastKill,Date)
                  VALUES (@JKillerID, 1, 1, 0, @JDeadNick, GETDATE())
                  END
                  ELSE Begin
                  UPDATE SRO_VT_SHARD_INIT.dbo._CharJobThiefsys SET ThiefPoints = ThiefPoints +1, Kills = Kills +1, LastKill = @JDeadNick, Date = GETDATE() WHERE CharID = @JKillerID
                  END
  
              END
              ELSE 
                  IF (@JKillerJobType = 3) /*HUNTER*/ 
                  BEGIN
                  IF (Not Exists(SELECT * FROM SRO_VT_SHARD_INIT.dbo._CharJobHuntersys Where CharID=@JKillerID))
                  BEGIN
                  INSERT SRO_VT_SHARD_INIT.dbo._CharJobHuntersys(CharID,HunterPoints,Kills,Deaths,LastKill,Date)
                  VALUES (@JKillerID, 1, 1, 0, @JDeadNick, GETDATE())
                  END
                  ELSE Begin
                  UPDATE SRO_VT_SHARD_INIT.dbo._CharJobHuntersys SET HunterPoints = HunterPoints +1, Kills = Kills +1, LastKill = @JDeadNick, Date = GETDATE() WHERE CharID = @JKillerID
                  END
  
              END 
              BEGIN
                  IF (@JDeadJobType = 1) /*TRADER*/ 
                  BEGIN
                  IF (NOT EXISTS(SELECT * FROM SRO_VT_SHARD_INIT.dbo._CharJobTradersys WHERE CharID=@CharID))
                  BEGIN
                  INSERT SRO_VT_SHARD_INIT.dbo._CharJobTradersys(CharID,TraderPoints,Kills,Deaths,LastKill,Date)
                  VALUES (@CharID, 0, 0, 1, 'NONE', GETDATE())
                  END
                  ELSE BEGIN
                  UPDATE SRO_VT_SHARD_INIT.dbo._CharJobTradersys SET TraderPoints = TraderPoints -0.5, Deaths = Deaths +1, Date = GETDATE() WHERE CharID = @CharID
                  END
                  END
              END 
              ELSE  
                  IF (@JDeadJobType = 2) /*THIEF*/ 
                  BEGIN
                  IF (NOT EXISTS(SELECT * FROM SRO_VT_SHARD_INIT.dbo._CharJobThiefsys WHERE CharID=@CharID))
                  BEGIN
                  INSERT SRO_VT_SHARD_INIT.dbo._CharJobThiefsys(CharID,ThiefPoints,Kills,Deaths,LastKill,Date)
                  VALUES (@CharID, 0, 0, 1, 'NONE', GETDATE())
                  END
                  ELSE BEGIN
                  UPDATE SRO_VT_SHARD_INIT.dbo._CharJobThiefsys SET ThiefPoints = ThiefPoints -0.5, Deaths = Deaths +1, Date = GETDATE() WHERE CharID = @CharID
                  END
  
              END
              ELSE 
                  IF (@JDeadJobType = 3) /*HUNTER*/ 
                  BEGIN
                  IF (NOT EXISTS(SELECT * FROM SRO_VT_SHARD_INIT.dbo._CharJobHuntersys WHERE CharID=@CharID))
                  BEGIN
                  INSERT SRO_VT_SHARD_INIT.dbo._CharJobHuntersys(CharID,HunterPoints,Kills,Deaths,LastKill,Date)
                  VALUES (@CharID, 0, 0, 1, 'NONE', GETDATE())
                  END
                  ELSE BEGIN
                  UPDATE SRO_VT_SHARD_INIT.dbo._CharJobHuntersys SET HunterPoints = HunterPoints -0.5, Deaths = Deaths +1, Date = GETDATE() WHERE CharID = @CharID
                  END
  
              END
          END
      END 
  </code></pre>
  
  <p>I get these errors:</p>
  
  <blockquote>
    <p>Msg 156, Level 15, State 1, Procedure _AddLogChar, Line 155<br>
    Incorrect syntax near the keyword 'ELSE'.</p>
    
    <p>Msg 156, Level 15, State 1, Procedure _AddLogChar, Line 194<br>
    Incorrect syntax near the keyword 'ELSE'.</p>
  </blockquote>
  
  <p>Side note : this is for the first <code>Else</code> command but the second one doesn't give error (the ones which are before IF (@JKillerJobType = 2) AND IF (@JDeadJobType = 2) !
  thanks !</p>