+4  A: 

ENDIF requires a space in MySQL doesn't it? i.e. END IF

David M
holy cow , how could I miss that :)
systemsfault
It's nigh on impossible to spot typos in your own code, don't worry. Let's hear it for pair programming or, if you can't do that, SO... :D
David M