I would start with the other reply in this thread and go from there. I agree with the other poster that the requirements don't seem complete -- it might be worth posting a sample of the data from the database and hand-hacking a result of what you'd want that turned into. Right now we can only see an example of it not working.