• Please let me know when you decide to post the DDL (CREATE TABLE) statements, sample data (INSERT INTO) for the tables, and expected results based on given inputs to the function and the sample data. Until then, there really isn't much I can do to really help you rewrite the function. I am a visual type of person. I need to see the starting point and the ending point so I make the necessary connections between the two and come up with a viable solution.