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)
 COMBINING ROWS..

Author  Topic 

8022421
Starting Member

45 Posts

Posted - 2009-06-04 : 03:44:54
HI,
I have a table in the below format

DATE NOTES
2009/02/03 MIGRATION1 IS FINE
2009/02/03 MIGRATION2 IS FINE
2009/02/04 MIGRATION3 IS FINE
2009/02/05 MIGRATION4 iS FINE


My requirement output should in the below format.

DATE NOTES
2009/02/03 MIGRATION1 IS FINE , MIGRATION2 IS FINE
2009/02/04 MIGRATION3 IS FINE
2009/02/05 MIGRATION4 iS FINE

Basically I need to sum up the Notes column based on the date, Can this be done with out using a cursor..Please advise..

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2009-06-04 : 03:45:44
see http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=81254


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

Go to Top of Page

kunal.mehta
Yak Posting Veteran

83 Posts

Posted - 2009-06-04 : 05:24:05
Hi,

try this


SELECT dt, STUFF( ( SELECT ',' + comments FROM test12 o where o.dt=o1.dt FOR XML
PATH('')),1 ,1, '') from test12 o1
group by dt
order by dt


create table test12(dt datetime,comments varchar(20))

Kunal
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2009-06-04 : 13:04:37
quote:
Originally posted by kunal.mehta

Hi,

try this


SELECT DISTINCT dt, STUFF( ( SELECT ',' + comments FROM test12 o where o.dt=o1.dt FOR XML
PATH('')),1 ,1, '') from test12 o1
group by dt
order by dt


create table test12(dt datetime,comments varchar(20))

Kunal

Go to Top of Page
   

- Advertisement -