MySql Error #1054 when adding new column to table using prepared statement
Remember that building SQL in this way is just building a String that happens to contain some text that your DBMS understands. 

Your new column name, >>lot&lt;&lt;, is just part of that SQL: 

SET @sql = CONCAT( 'ALTER TABLE ipp_sorted ADD `lot` INT PRIMARY KEY AUTO_INCREMENT=', @lot );


Leaving >>lot&lt;&lt; outside the string literal, the DBMS is trying to interpret it as a column in something or other (variables being prefixed with '@' signs) but it can't find such a column, so gives up with this error.