Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
BigRetina
Posting Yak Master
144 Posts |
Posted - 2003-05-04 : 03:21:51
|
| Salute..I need to view each employee in Employees table with his children from EmployeeFamily table like :EmployeeId Children---------- ----------1 John,Mia,Karla2 Sofi3 Peter,Sandy...etc...Can I do this in ONE statement???I looked into the COALESCE use in this forum i ended up with the following :DECLARE @ChildrenList varchar(100)SELECT @ChildrenList = COALESCE(@ChildrenList + ', ', '') + CAST(ChildName AS varchar(5))FROM EmployeeFamilyWHERE EmployeeId IN (Select EmployeeId from Employees)SELECT @ChildrenList AS ChildrenBUT...this solution shows ALL children for all employees in ONE COMMA SEPERATED STRING!..NOT WHAT I WANT!..Any ideas??Thanks IN Advance |
|
|
jsmith8858
Dr. Cross Join
7423 Posts |
Posted - 2003-05-04 : 08:49:12
|
| Check out this article:http://www.sqlteam.com/item.asp?ItemID=11021then read the comments -- posted by Byrmol is a function that will do exactly what you want. I recommend the function if you have Sql 2000, it works very well, and is easy to use.- Jeff |
 |
|
|
|
|
|