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)
 Concat function

Author  Topic 

rksingh024
Yak Posting Veteran

56 Posts

Posted - 2002-04-17 : 06:02:32
Hi,

<<
select au_lname from pubs..authors
where au_lname like 'g%'
>>

will give you three rows. Is it possible to get the records in one row values separated by comma i.e. "Green,Greene,Gringlesby"

Or can we write some concat function that works like a group function e.g. like sum, avg.


Ramesh

Ramesh Singh

VyasKN
SQL Server MVP &amp; SQLTeam MVY

313 Posts

Posted - 2002-04-17 : 06:23:45
Here's one way of doing it:
http://vyaskn.tripod.com/code.htm#cat

--
HTH,
Vyas
Check out my SQL Server site @
http://vyaskn.tripod.com
Go to Top of Page

rksingh024
Yak Posting Veteran

56 Posts

Posted - 2002-04-17 : 06:45:26
There is one line missing in my problem.

I want to get the result in a single t-sql statement. So that I can use it in another select statement. e.g.

<<
select id,name,
(select concat(skill_desc)from skills where employeeid=e.id) as skills
from employee e
>>

this should return me the resultset as
-----------
1 Abc sql,asp
2 Pqr sql,vb,xml
----------



Ramesh Singh
Go to Top of Page

AndrewMurphy
Master Smack Fu Yak Hacker

2916 Posts

Posted - 2002-04-17 : 07:50:40
this problem has been answered here many times
....search for CSV....there's even a FAQ on it!

Go to Top of Page

robvolk
Most Valuable Yak

15732 Posts

Posted - 2002-04-17 : 08:16:09
This should help:

http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=9978

You CANNOT do the full concatenation in one SELECT statement, you need some kind of loop (not necessarily a cursor, but a loop nevertheless) The above link has several options that will provide the results you want.

Go to Top of Page
   

- Advertisement -