Additionally, please try to avoid using too many subqueries, as they can negatively impact the performance of your query. Consider using SQL Server Common Table Expressions (CTEs) or table variables as alternatives for better efficiency and please avoid using function on your where clause.