Hi PT Welcome to Q&A Forum; this is a great place to get support, answers, and tips. Thank you for posting your question; I'll be more than glad to help you out.
To adequately assist you with your issue/problem, it would be constructive for us to reproduce your scenario.
Please provide us with at least the following things:
- DDL and sample data population, i.e., CREATE table(s) plus INSERT, T-SQL statements.
- What you need to do, i.e., logic and your attempt implementation of it in T-SQL.
- Desired output based on the sample data in #1 above.
- Your SQL Server version (SELECT @@version;)
You should provide us with at least those two relevant tables and 1-3 demo parents with related demo childs (or actual data if there is no sensitive data in it) I hope my answer is helpful to you,
Your Bjoern Peters
If the reply was helpful, please upvote and/or accept it as an answer, as this helps others in the community with similar questions. Thanks!