• Could you please provide the DDL (CREATE TABLE statement) for the target table of the procedure and the expected results based on the sample data input provided for the procedure.

    I am thinking that you may have over thought what was needed but need to know what you are trying to accomplish to be sure. You have provided a good start but there are just a few things missing that if provided will offer us a clearer picture.