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
 SQL Server 2000 Forums
 SQL Server Development (2000)
 mysql equivalent of "group_concat()" in sql server

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2005-04-18 : 07:13:32
Naga Kiran writes "Is there any equivalent in SQL Server like "group_concat()" in mysql..

i have a table with columns author_id,book_title..
Now i want to make a query which will do
grouping by author_id and want to display the list of books authored by him delimited by a seperator in a seperate column
can i achieve this without using procedures in SQL Server

Thanx in advance"

AndrewMurphy
Master Smack Fu Yak Hacker

2916 Posts

Posted - 2005-04-18 : 08:50:00
any chance of sample data???...and matching expected results?
or are we to be "most-excellent-mind-readers"???
Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2005-04-18 : 09:41:14
http://dev.mysql.com/doc/mysql/en/group-by-functions.html

If I'm reading this correctly


USE Northwind
DECLARE @x varchar(8000)
SELECT @x = COALESCE(@x+', ','')+ISNULL(ShipName,'') FROM ORders
SELECT @x




Brett

8-)
Go to Top of Page

jsmith8858
Dr. Cross Join

7423 Posts

Posted - 2005-04-18 : 10:21:13
>>grouping by author_id and want to display the list of books authored by him delimited by a seperator in a seperate column

The easiest way is to use a technique similiar to what Brett has posted, but put it into a UDF which accepts an AuthorID as a parameter.

Then, for your final desired result, you simply query the Authors table and call the UDF for each AuthorID, which will return the comma-separated list of book.

Also, it is often much, much easier and more efficent to do formatting like this at the presentation layer.

- Jeff
Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2005-04-18 : 10:54:01
quote:
Originally posted by X002548

If I'm reading this correctly



I guess reading may have been the wrong choic of words...

But Jeff's suggestion with the udf would be the way to go....

Know what a udf is?



Brett

8-)
Go to Top of Page
   

- Advertisement -