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
 hi every one

Author  Topic 

raky
Aged Yak Warrior

767 Posts

Posted - 2008-01-02 : 04:00:03
my table containing like this
a 1
a 2
a 3
a 4
a 5
b 1
b 2
b 3
b 4
i want output like this
a 1,2,3,4,5
b 1,2,3,4
thanks in advance

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2008-01-02 : 04:04:15
http://sqlblog.com/blogs/adam_machanic/archive/2006/07/12/rowset-string-concatenation-which-method-is-best.aspx
http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=81254


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

Go to Top of Page

raky
Aged Yak Warrior

767 Posts

Posted - 2008-01-02 : 04:31:02
thanks plz tel in simple way
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2008-01-02 : 04:35:01
quote:
Originally posted by raky

thanks plz tel in simple way



Where do you want to show data?
Which one do you find it difficult?

Madhivanan

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

raky
Aged Yak Warrior

767 Posts

Posted - 2008-01-02 : 04:42:29
thanks
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-01-02 : 04:56:14
If you are still finding it difficult, one method:-

SELECT DISTINCT t1.[name],LEFT(List.t2,LEN(List.t2)-1) AS 'IdList'
FROM @sample t1
CROSS APPLY (SELECT CAST(name_id AS varchar(5)) + ','
FROM @sample
WHERE [name]=t1.[name]
FOR XML PATH(''))List(t2)
Go to Top of Page

raky
Aged Yak Warrior

767 Posts

Posted - 2008-01-02 : 05:56:24
thanks
Go to Top of Page

ranganath
Posting Yak Master

209 Posts

Posted - 2008-01-02 : 07:38:51
Hi,

Try This one Also

DECLARE @StrConcat TABLE (col1 nvarchar(10),col2 nvarchar(10))

insert into @StrConcat
select 'db1','host1'
union all select 'db1','host2'
union all select 'db1','host3'
union all select 'db2','host1'
union all select 'db2','host2'
union all select 'db3','host2'
union all select 'db3','host3'


select col1, stuff( ( select ','+ col2 from @StrConcat t1 where t2.col1 = t1.col1 for xml path('')),1,1,'') Val
from @StrConcat t2
group by col1
order by col1
Go to Top of Page

raky
Aged Yak Warrior

767 Posts

Posted - 2008-01-02 : 23:34:26
thank u
Go to Top of Page
   

- Advertisement -