title: Error Code: 1815 Internal error: JSON wrapper: unexpected type in procedures
body: <p>This is the procedure that i have written it gives
   Error Code: 1815 Internal error: JSON wrapper: unexpected type
   when else case executes in this query
  but it works fine when I change null into {}.</p>
  
  <pre><code>**SELECT CASE
  WHEN (select count(*) from user_attendance a where a.user_id =userId order by a.user_attn_id desc )!=0 then (select a.bays from user_attendance a where a.user_id =userId order by a.user_attn_id desc limit 1) ELSE null END) );**
  </code></pre>
  
  <p>As well as it works when I run it alone as </p>
  
  <pre><code>**insert into user_attendance(user_id,bays,modified_at,modified_by) values(16,(SELECT CASE
    WHEN (select count(*)  from user_attendance a where a.user_id =1 order by a.user_attn_id desc )!=0 then  (select a.bays  from user_attendance a where user_id =1 order by a.user_attn_id desc limit 1)
    ELSE null
  END),now(),16);**
  </code></pre>
  
  <p>I don't why its showing such type of behavior</p>
  
  <pre><code>DROP PROCEDURE `a`.`getTechnicianAttendance`;
  
  DELIMITER $$
  
   CREATE PROCEDURE getTechnicianAttendance()
  BEGIN
  DECLARE users_count  INTEGER DEFAULT 0;
  DECLARE finished INTEGER DEFAULT 0;
  
  SELECT count(*) into users_count
  FROM user_attendance
  WHERE date = current_date();
  
  IF users_count = 0 THEN
  
      Begin
      DECLARE userId INTEGER DEFAULT 0;
      DECLARE user_id_cursor CURSOR FOR
      select users.user_id from users left outer join user_roles on user_roles.user_id = users.user_id where user_roles.role_id = (select role_id from roles  where roles.role_name = 'Technician');
  
      DECLARE CONTINUE HANDLER FOR NOT FOUND SET finished = 1;
  
      open  user_id_cursor;
  
      user_ids: LOOP
      FETCH user_id_cursor INTO userId;
  
      IF finished = 1 THEN
      LEAVE user_ids;
      END IF;
  
      insert into `autoscope`.`user_attendance` (user_id, 
        date,
        bays
         )   
      values (
        userId,
        current_date(),
             (SELECT CASE
     WHEN (select count(*)  from user_attendance a where a.user_id =userId order by a.user_attn_id desc )!=0 then   (select a.bays  from user_attendance a where a.user_id =userId order by a.user_attn_id desc limit 1)
     ELSE null
   END)
        );
  
  
       END LOOP user_ids;
  
      CLOSE user_id_cursor;
      End;
      END IF;
  </code></pre>
  
  <p>END $$</p>