I am using a timetabling system with SQL Server 2000 backend I need to list events with tutors and rooms next to them this can be more than 1 so could do with turning the multiple rows of rooms and tutors into + separated lists. I have used the code below in the past:
DECLARE @Tutors as varchar(8000)
SELECT @Tutors = isnull(@Tutors + ' + ', '') + name
FROM (
SELECT CT_EVENT_STAFF.event_id, CT_EVENT_STAFF.weeks,
CT_STAFF.unique_name, CT_STAFF.name
FROM celcat200809.dbo.CT_EVENT_STAFF AS CT_EVENT_STAFF
LEFT OUTER JOIN celcat200809.dbo.CT_STAFF AS CT_STAFF
ON CT_EVENT_STAFF.staff_id = CT_STAFF.staff_id
WHERE event_id = @eventID
) As data_set
print @Tutors
The event_id being the unique event, this will only work when I know the exact ID, I can't run it for every ID.
Is there a way to do this for each individual event_id without cursors. I have seen a possible solution to this in using a UDF unfortunately my second problem is the timetabling system (CELCAT) creates a new database for each year (I know don't ask) so I am going to have to make the SQL dynamic i.e next years database would be celcat200910, I believe dynamic SQL cannot be run in UDF's.
Please remember this is SQL Server 2000