I'm trying to populate the Employees
field in the temporary table using a subquery that comma separates the employee ids. My syntax is not correct.
What is the correct syntax to get the comma separated employee ids to insert into the temporary table? Here is my code:
declare @CommaSeperatedList varchar(max)
create table #tmp
(
ManagerId int,
Employees varchar(max)
)
insert into #tmp (ManagerId, Employees)
select
m.Id,
select @CommaSeperatedList = COALESCE(@CommaSeperatedList + ', ', '') + cast(emp.Id as varchar from emp select @CommaSeperatedList
from Manager m
inner join Employee emp on
m.EmployeeId = emp.Id