Fix stored procedure bug