• Welcome to SSC. As it appears you are new here there are some things you need to do to helps help you and for you to get better answers to your problem.

    First, start by reading the first article I reference below in my signature block regarding asking for help. The instructions in that article will help with the information you need to post and how to post it.

    We really do need the DDL (CREATE TABLE) statement for the table(s) involved, sample data (as a series of INSERT INTO statements) for the table(s) involved, and the expected results based on the sample data. Please note, we aren't asking for actual, confidential data as sample data. We just want data that is representative of your problem domain and the problem you are trying to solve.

    You do this and you will get good answers in return plus the code provided will be tested against the data you provided.