Hi @siva rama krishna reddy tangirala ,
Welcome to the Microsoft TSQL Q&A Forum!
The description of your problem is very clear, but you did not provide the corresponding table code and data code, we can not do the test and find the problem.
In addition, when you post a question, please provide a minimal example for testing and the output you expect.
Echo