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
 Transact-SQL (2000)
 Column Concatenate

Author  Topic 

karthickbabu
Posting Yak Master

151 Posts

Posted - 2009-05-14 : 00:36:14
My Tables values are like these

A1 AA
A1 AB
A1 AC
A2 BA
A2 BB
A3 CA


I need output like as below

A1 AAABAC
A2 BABB
A3 CA

====================================================
you realize you've made a mistake, take immediate steps to correct it.

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2009-05-14 : 02:16:03
see
http://sqlblog.com/blogs/adam_machanic/archive/2006/07/12/rowset-string-concatenation-which-method-is-best.aspx


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

raky
Aged Yak Warrior

767 Posts

Posted - 2009-05-14 : 02:27:32
declare @temp table ( Id varchar(30), Val varchar(30))

insert into @temp
select 'A1', 'AA' union all
select 'A1', 'AB' union all
select 'A1', 'AC' union all
select 'A2', 'BA' union all
select 'A2', 'BB' union all
select 'A3' ,'CA'

select distinct id ,stuff( (select ''+val from @temp where id = t.id for xml path('')),1,0,'') as val
from @temp t
Go to Top of Page

karthickbabu
Posting Yak Master

151 Posts

Posted - 2009-05-14 : 02:44:38


Thanks for your link

====================================================
you realize you've made a mistake, take immediate steps to correct it.
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2009-05-14 : 02:47:45
quote:
Originally posted by raky

declare @temp table ( Id varchar(30), Val varchar(30))

insert into @temp
select 'A1', 'AA' union all
select 'A1', 'AB' union all
select 'A1', 'AC' union all
select 'A2', 'BA' union all
select 'A2', 'BB' union all
select 'A3' ,'CA'

select distinct id ,stuff( (select ''+val from @temp where id = t.id for xml path('')),1,0,'') as val
from @temp t


This wont work in SQL Server 2000

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -