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 2005 Forums
 Transact-SQL (2005)
 Merging contents

Author  Topic 

paulmoss
Starting Member

14 Posts

Posted - 2011-12-15 : 12:44:55
I am currently trying to create a script that will merge the contents of indivial rows based on the contents of another. For example we have the following information

ID Dated Notes
1 01/01/11 Started Project
1 15/01/11 Have Spoken to Mike all ok
1 25/02/11 Mike has won the contract
2 01/01/11 Started Project
2 31/01/11 Project lost to competitor

What I want to out put is the following

ID Notes
1 01/01/11 - Started Project. 15/01/11 - Have Spoken to Mike all is ok. 25/02/11 - Mike has won the project
2 01/01/11 - Started Project. 31/01/11 - Project lost to competitor

Or into a similar format. Any help that you can provide would be greatley appreciated


Many thanks

Paul

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2011-12-15 : 12:49:24
[code]
SELECT ID,
STUFF((SELECT '.' + CONVERT(varchar(8),Dated,3) + ' - ' + Notes FROM Table WHERE ID = t.ID ORDER BY Dated FOR XML PATH('')),1,1,'')
FROM (SELECT DISTINCT ID FROM Table)t
[/code]

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -