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)
 Set Based solution?

Author  Topic 

Tapalotapus
Starting Member

22 Posts

Posted - 2005-10-10 : 00:25:32
What I'm trying to do is group by the date (DTE) but I want the text value (TEXTER) for each matching date to be strung together with a comma delimiter. I know I can do a group by the date then loop through the records for each date and build the string but I know there has to be a set based way to do this easily?

Thanks


CREATE TABLE #wowo (
RowID int IDENTITY(1,1),
DTE DATETIME,
TEXTER NVARCHAR(10)
)

INSERT INTO #wowo(DTE,TEXTER)VALUES('1/1/05', 'A')
INSERT INTO #wowo(DTE,TEXTER)VALUES('1/1/05', 'B')
INSERT INTO #wowo(DTE,TEXTER)VALUES('1/1/05', 'C')
INSERT INTO #wowo(DTE,TEXTER)VALUES('1/2/05', 'A')
INSERT INTO #wowo(DTE,TEXTER)VALUES('1/2/05', 'B')
INSERT INTO #wowo(DTE,TEXTER)VALUES('1/2/05', 'C')
INSERT INTO #wowo(DTE,TEXTER)VALUES('1/2/05', 'D')
INSERT INTO #wowo(DTE,TEXTER)VALUES('1/3/05', 'A')

------ Expected results ----------
DTE TEXTER
1/1/05 A,B,C
1/2/05 A,B,C,D
1/3/05 A

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2005-10-10 : 00:46:08
Refer this
http://sqljunkies.com/WebLog/amachanic/archive/2004/11/10/5065.aspx?Pending=true

Madhivanan

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

Tapalotapus
Starting Member

22 Posts

Posted - 2005-10-10 : 00:57:41
Thanks Madhivanan, I will read it over.
Go to Top of Page
   

- Advertisement -