So, I already received a solution to my problem in Part A, but I have additional requirements. I tried messaging the people who helped me there, but I guess since I marked the thread as solved and gave them reps, they aren't replying anymore. So have started a new thread for someone to follow up on the solution provided.
The 2 solutions provided are with filenames ending PartA. And the query that I have for this thread is in the file PartB.
Link to: Part A
I hope someone can look into these files and help me out on this.
Bookmarks