A Microsoft extension to the ANSI SQL language that includes procedural programming, local variables, and various support functions.
I'm not sure what you have in mind with CASE here. But I don't think that is a good candidate here.
I did start to rewrite your query have the UNION in a CTE, and have all aggregation after the CTE. This is often a great way to write queries like these.
But when I looked closer, I found some issues in your query that made me stop. First, what you posted is not correct syntactically. There should be a closing parenthesis followed by an alias for the derived table. That's a trivial error, but it makes me uncertain if there is more missing.
Also, this:
select SalesRepAccId, PreSellingRoute, count(distinct SalesRepAccId)SalesRepCount
from @SyncDetails
Because you are grouping on SalesRepAccId, COUNT(DISTINCT SalesRepAccId) will always be 1, so you may have something else in mind.
Maybe you should continue to work with your query in its current form and make sure that it returns the correct result before you ask further.
Also:
where convert(varchar,TransactionDate,23)=convert(varchar,@apl ,23)
This is not wrong, but the conversion to varchar precludes the usage of any index on TransactionDate. Here is a better way to write the same thing:
where cast(TransactionDate AS date) = cast(@date as date)