Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Build Comment and associate to an owner without using Cursor 1

Status
Not open for further replies.

MeanGreen

IS-IT--Management
Sep 12, 2002
672
US
I have a table with multiple comments that I want to merge into one comment per owner WITHOUT using a CURSOR. Here is my sample table:

create table #test
(Owner char(1),
Seq int,
comment varchar(25))

insert #test values ('A',1,'This is')
insert #test values ('A',2,'a')
insert #test values ('A',3,'Test')
insert #test values ('B',1,'Second of')
insert #test values ('B',2,'many test')
insert #test values ('C',1,'Third test only')

What I want to see for output is:

A, This is a Test
B, Second of many test
C, Third test only

Again, this is without using a CURSOR. I can get the comment ONLY per owner with the following code:

declare @comment varchar(2500)
set @comment = ''
select @comment = @comment + comment + ' '
from #test
where owner = 'A'
order by owner,seq
select @comment

Any help here would be appreciated.
 
Build a function that returns the full comment for a particular user, using the code you have already written. Then use that function in your select:

Code:
SELECT DISTINCT owner, dbo.getComment(owner) AS comment
FROM table

--James
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top