fikir
Programmer
- Jun 25, 2007
- 86
I have a table called
emplyee
empId empname
1 John
2 Sean
3 Merry
each employee participate in one or more different projects
I am planning to get the list of projects the employee are taking part
I wrote a function fnProj which accepts an emplyee Id and returns all projects the employee is participating,
and I wrote this query to get all the projects
declare @projects varchar(2000)
set @projects = ''
select @projects = @projects + fnProj(empId) + ', '
from employee
select @projects
the query is returning the projects, but the problem is because many employees are participating in one project at the same time, that projects name is repeating many time
but I want the @projects to be a list of unique projects.
i.e the projects name appear ones even though many emplyees taking part.
the list should look like
proj1, proj2, proj3
Thanks
emplyee
empId empname
1 John
2 Sean
3 Merry
each employee participate in one or more different projects
I am planning to get the list of projects the employee are taking part
I wrote a function fnProj which accepts an emplyee Id and returns all projects the employee is participating,
and I wrote this query to get all the projects
declare @projects varchar(2000)
set @projects = ''
select @projects = @projects + fnProj(empId) + ', '
from employee
select @projects
the query is returning the projects, but the problem is because many employees are participating in one project at the same time, that projects name is repeating many time
but I want the @projects to be a list of unique projects.
i.e the projects name appear ones even though many emplyees taking part.
the list should look like
proj1, proj2, proj3
Thanks