Hi Deushade,
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.
As Olaf and Percy already stated, please answer the following:
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:
(1) DDL and sample data population, i.e., CREATE table(s) plus INSERT, T-SQL statements.
(2) What you need to do, i.e., logic and your attempt implementation of it in T-SQL.
(3) Desired output based on the sample data in #1 above.
(4) Your SQL Server version (SELECT @@version;)
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!