I would follow Jake's suggestion, from a previous post of the exact same question, and simplify your script to more easily debug your issue with the SQL clause. Once that problem has been resolved I would work towards getting your more complex code working.