Thank very much for your input, after that was cleared up.
I started reading the script again (7 times) before found out I missed a endif .
Pretty weird for an ENDSELECT without SELECT error when I was missing a ENDIF.