Your code is what we commonly refer to as a "train wreck" (no offense intended -- we all have our bad moments), but now that you have learned how to post legibly, there's hope. I tried to provide some help in the initial thread where you started posting this puzzle:
Re^7: SQL queries using dynamic array (too long to be of interest to others).
Good luck.