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.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Concatenate repreating values of column

Author  Topic 

cyberbeing
Starting Member

2 Posts

Posted - 2011-07-16 : 23:56:57
Hi everyone,
I have this problem of displaying distinct column and have the other corresponding column concatenated.. here is the sql statement

SELECT titles.title, authors.au_lname as Authors
FROM authors INNER JOIN
titleauthor ON authors.au_id = titleauthor.au_id INNER JOIN
titles ON titleauthor.title_id = titles.title_id

The result is like this..
Title Authors

The Gourmet microwave O'Leary
The Gourmet microwave Gringlesby
The Gourmet microwave Yokomoto

but i want it to look something like this....
Title Authors

The Gourmet microwave O'leary,Gringlesby,Yokomoto

I need help please, Thank you

mohdowais
Sheikh of Yak Knowledge

1456 Posts

Posted - 2011-07-17 : 04:34:47
There are many ways to do this, none of them are easy though. The simplest technique is probably this one: http://blog.sqlauthority.com/2009/11/25/sql-server-comma-separated-values-csv-from-table-column/ but I would recommend you read up on the others as well: http://www.simple-talk.com/sql/t-sql-programming/concatenating-row-values-in-transact-sql/

OS
Go to Top of Page

cyberbeing
Starting Member

2 Posts

Posted - 2011-07-17 : 10:33:17
Thanks
Go to Top of Page
   

- Advertisement -