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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Selecting a list into a column

Status
Not open for further replies.

NewFromMattel

Programmer
Jun 24, 2003
41
US
Ok, here's a stumper for me... (probably pretty simple to you SQL gurus)

I have a table of entries, single rows with PK of baseID.
I have another table of categories with PK of catID
I have a "join" table entrycatjoin that has those two PKs.

entries are a 1 to many categories relationship.
what I need is to get all the info for each row of entries, and additionally a column of aggregated categories associated with that entry.

So doing a standard join
select *
from entries e join entrycatjoin ecj on e.baseID = ecj.baseID join categories c on ecj.catID = c.catID

brings back too many rows because there is a row for each category. I want to concatenate the category (description but I can get that) into a list in one column for each row from entries.

I hope I explained it well. I have always used my front end code to do this before, but need to do it in sql now.

Thanks
 
Check out faq183-2146. Good luck!

--Angel [rainbow]
-----------------------------------
Behold! As a wild ass in the desert
go forth I to do my work.
--Gurnie Hallock (Dune)
 
Thanks for the pointer. I'm sorry I didn't check the FAQ first.

But I'm having a little difficulty, with this section:
While @ln<=@mln
Begin
Update #tmp
Set CombinedLine=CombinedLine+CAST(j.Worklog_ID AS varchar)+' '
From #tmp a Join MK_WorklogCategory j ON a.catID = j.WorklogCategory_ID
Where a.catID=@ln

Select @ln=@ln+1
End

The #tmp table is being created, and the catID vals are being inserted. But the update isn't happening. Now I'm kinda over my head cause I've never used the FROM after the UPDATE without a SELECT. Any ideas?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top