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 2008 Forums
 Transact-SQL (2008)
 select

Author  Topic 

arkiboys
Master Smack Fu Yak Hacker

1433 Posts

Posted - 2012-03-14 : 04:26:14
Hi,
This is my table with some test data as follows:

tblMain

ID ValueField
------------------
122 'value1'
122 'value2'
122 'value3'
...

432 'somevalue'
...

Question:
How can I return

ID ValueField
------------------
122 'value1', 'value2', 'value3'
...
432 'somevalue'

Thanks

GilaMonster
Master Smack Fu Yak Hacker

4507 Posts

Posted - 2012-03-14 : 04:47:50
Read up on FOR XML PATH as a method of string concatenation. There's a good article at Simple-talk.com

--
Gail Shaw
SQL Server MVP
Go to Top of Page

nasim.sona
Starting Member

7 Posts

Posted - 2012-03-14 : 05:45:36
your requirement is something which requires aggregate function to concatenate , but unluckily we don't have such function in sql-server (or I am not aware).

select id,concatenateall(valuefield) from table
group by id

-Nasim
Go to Top of Page
   

- Advertisement -