2

For example, I've 2 tables as follows-

Table: Parents

-------------------------
| ParentId | ParentName |
-------------------------
| 1        |      abc   |
------------------------- 
| 2        |      xyz   |
------------------------- 

Table: Childs

----------------------------------
| ChildId | ChildName | ParentId |
----------------------------------
| 1       |      p    |    1     |
---------------------------------- 
| 2       |      q    |    1     |
---------------------------------- 

I would to have a Query: Parents_Childs

--------------------------
| ParentName | ChildName |
--------------------------
|   abc      |   p, q    | 
--------------------------

Is there any way to do it in SQL Server 2008?

s.k.paul
  • 7,099
  • 28
  • 93
  • 168
  • SQL Server... GROUP BY, with STUFF? – jarlh Jul 02 '15 at 07:59
  • @jarlh `STUFF`, yes, but in addition you need to trick with XML output. – SQL Police Jul 02 '15 at 08:02
  • This is really one of the most-asked questions. (IMHO, Microsoft should create a designated simple function for creating such results). Here is another link: http://stackoverflow.com/questions/1817985/how-do-i-create-a-comma-separated-list-using-a-sql-query – SQL Police Jul 02 '15 at 08:07
  • Still, upvote from me, because the question per se is very clear. – SQL Police Jul 02 '15 at 08:09
  • @SQLPolice , me too. Other questions might be similar with this to some extent, but not exact. This is a precise problem. So, upvote from me also. – Code It Jul 02 '15 at 08:15

0 Answers0