This new line produced a syntax error near distinct:
select count(distinct Left(ToName,2)) OVER(PARTITION BY TransTime, DriverNo) as CustCount
I had to write it as:
select distinct count(Left(ToName,2)) OVER(PARTITION BY TransTime, DriverNo) as CustCount
You...