Hi It worked elsewhere because the other host was using microsoft SQL. wolstech's message made me double check that I was using MySQL, which I was not. My code was for Microsoft SQL. I have since changed the code and all works as it should. Thank you for your help Jack.