Unfortunately, there's not much we can do without more details, DDL, sample data and expected results based on that sample data. These things will allow us to give you a better and faster answer. For more information, please read the article linked in my signature and come back again. 😉