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)
 string concatenation

Author  Topic 

ponnurajs
Starting Member

6 Posts

Posted - 2007-03-02 : 06:08:58
Hai,

I need a query to conatenate same column values available in 3 records. ie.,

My record like this.

Name Item
Raj A
Raj B
Raj C

My output will be

Raj A,B,C

whether this is possible with in a single query.
Any one can help me for this.

Thanks in advance

Regards,
Raju.

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2007-03-02 : 06:14:32
Yes, this is possible and have been asked almost a million times here at SQLTeam.
http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=53885


Peter Larsson
Helsingborg, Sweden
Go to Top of Page

mahesh_bote
Constraint Violating Yak Guru

298 Posts

Posted - 2007-03-02 : 08:30:10
try this ...


create table #test
(num numeric
,txt varchar(10))

insert into #test
select 1, 'A'
union
select 1, 'B'
union
select 1, 'C'

declare @str varchar(50)
select @str = case when @str is null then txt else @str + ', ' + txt end from #test
select num, @str as txt from #test
group by num

drop table #test

Mahesh
Go to Top of Page
   

- Advertisement -