title: if else inside if else sql
body: <p>Do you know why ELSE is higlihted in my code? Last ELSE. Im trying to create procedure but i have problem with if clause</p>
  
  <p>Can somebody help me? I'm aware that solution with max value of id and adding 1 to it is not good but it is temporary. Later i will try to implement better way</p>
  
  <pre><code>CREATE PROCEDURE dodajAuto
      (@marka VARCHAR, 
       @model VARCHAR, 
       @kolor VARCHAR, 
       @moc INT, 
       @dataProdukcji DATETIME, 
       @cena DECIMAL, 
       @typ VARCHAR, 
       @przebieg INT)
  AS
  BEGIN
      DECLARE @tmpMarka VARCHAR = (SELECT MARKA FROM MARKA WHERE MARKA=MARKA)
      DECLARE @tmpModel VARCHAR = (SELECT MODEL FROM MODEL WHERE MODEL=MODEL)
  
      DECLARE @tmpIdModelu INT = (SELECT IDMODELU FROM MODEL WHERE MODEL=MODEL)
      DECLARE @tmpIdMarki INT = (SELECT IDMARKI FROM MARKA WHERE MARKA=MARKA)
  
      DECLARE @tmpLastIdSamochodu INT = (SELECT MAX(IDSAMOCHODU) FROM SAMOCHOD)
      DECLARE @tmpLastIdModelu INT = (SELECT MAX(IDMODELU) FROM MODEL)
      DECLARE @tmpLastIdMarki INT = (SELECT MAX(IDMARKI) FROM MARKA)
  
  
      IF (@tmpMarka IS NOT NULL)
          IF (@tmpModel IS NOT NULL)
              INSERT INTO SAMOCHOD 
              VALUES (@tmpLastIdSamochodu+1, @tmpIdModelu, @kolor, @moc, @przebieg, @dataPRodukcji, @typ);
          ELSE
              INSERT INTO MODEL 
              VALUES (@tmpLastIdModelu+1, @tmpIdMarki, @model, @cena)
  
      SET @tmpIdModelu = (SELECT IDMODELU FROM MODEL WHERE MODEL = MODEL)
  
      INSERT INTO SAMOCHOD 
      VALUES (@tmpLastIdSamochodu+1, @tmpIdModelu, @kolor, @moc, @przebieg, @dataProdukcji, @typ);
  
      ELSE --THIS IS WHERE SYNTAX IS HIGLIHTED, 
  
      INSERT INTO MARKA VALUES (@tmpLastIdMarki+1, @marka)
  
      SET @tmpIdMarki  = (SELECT IDMARKI FROM MARKA WHERE MARKA = MARKA)
  
      INSERT INTO MODEL 
      VALUES (@tmpLastIdModelu+1, @tmpIdMarki, @model, @cena)
  
      SET @tmpIdModelu = (SELECT IDMODELU FROM MODEL WHERE MODEL = MODEL)
  
      INSERT INTO SAMOCHOD 
      VALUES (@tmpLastIdSamochodu+1, @tmpIdModelu, @kolor, @moc, @przebieg, @dataProdukcji, @typ);
  </code></pre>