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)
 Quiry

Author  Topic 

dewacorp.alliances

452 Posts

Posted - 2007-01-06 : 19:23:50
Hi all

I need some guidance how to the following query. Basically, I got table as follow:

Customers:
CustomerID,
CustomerName

CustomerGenres
CustomerID
GenreID

Genres:
GenreID
GenreName

I want to display a list that as follow:
"John Doe", "Pop, "Rock", Classical"
"Val", "Rock"

Thanks

nr
SQLTeam MVY

12543 Posts

Posted - 2007-01-06 : 21:52:33
create function csvtbl
(@CustomerID as int)
returns varchar(8000)
AS
begin
declare @csv varchar(8000)
select @csv = coalesce(@csv+',','') + GenreName
from Genres g
join CustomerGenres gg
on g.GenreID = gg.GenreID
where CustomerID = @CustomerID
return @csv
end
go

select CustomerName, dbo.csvtbl(CustomerID)
from Customers

==========================================
Cursors are useful if you don't know sql.
DTS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page
   

- Advertisement -