I am writingansql query using CTE with pivot and i'm getting following errors :
Msg 156, Level 15, State 1, Line 13
Incorrect syntax near the keyword 'select'.
Msg 102, Level 15, State 1, Line 13
Incorrect syntax near ')'.
and my Query ;
with T as
(select a.[EmployeeID],a.[NationalIDNumber],a.[Title],a.[ManagerID]
from [HumanResources].[Employee] as a
inner join
HumanResources.EmployeeAddress as b on a.EmployeeID =b.EmployeeID )
select * from T
pivot ( sum(ManagerID)for [Title] in (select title from [HumanResources].[Employee]as a) ) aspvt
Please anyone help me to short out this error thanks