insert row if table is empty, else update row (mysql)
got it working but there might be better ways

CREATE PROCEDURE simple6(IN name VARCHAR(20))
BEGIN

SET @sql_text = concat('SELECT endtime INTO @endtime1 FROM ',name,'big order by endtime DESC LIMIT 1');
PREPARE stmt FROM @sql_text;
EXECUTE stmt;

if @endtime1 IS NULL
then

SET @sql_text2=concat('INSERT INTO ',name,'big (starttime,endtime) SELECT starttime,endtime FROM ',name,' ORDER BY endtime DESC LIMIT 1');
PREPARE stmt2 FROM @sql_text2;
EXECUTE stmt2;
DEALLOCATE PREPARE stmt2;

else
SET @sql_text3= concat('set @cat:= (IF(TIMESTAMPDIFF(SECOND,(SELECT endtime from ',name,'big order by endtime DESC limit 1),(SELECT starttime from ',name,' order by starttime DESC limit 1)) &lt; 5,1,0))');
PREPARE stmt3 FROM @sql_text3;
EXECUTE stmt3;
DEALLOCATE PREPARE stmt3;

if @cat !=0
THEN
SET @sql_text4=concat('UPDATE ',name,'big SET endtime = (SELECT endtime FROM ',name,' ORDER BY endtime DESC LIMIT 1) ORDER BY ID DESC LIMIT 1');
PREPARE stmt4 FROM @sql_text4;
EXECUTE stmt4;
DEALLOCATE PREPARE stmt4;

else
SET @sql_text5=concat('INSERT INTO ',name,'big (starttime,endtime) SELECT starttime,endtime FROM ',name,' ORDER BY endtime DESC LIMIT 1');
PREPARE stmt5 FROM @sql_text5;
EXECUTE stmt5;
DEALLOCATE PREPARE stmt5;

end if;
end if;
DEALLOCATE PREPARE stmt;

END\\