Did you copy everything including the text before the sql. Just copy from
SELECT @sortorder:=max(sort_order) down and paste and hit send. This one seems to not be able to copy everything and hit send. Just copy the code.