Page 1 of 1

TVF_ActivityRooms

Posted: Thu Mar 02, 2017 10:30 pm
by robinwilson16
Returns the rooms attached to an activity as a single comma separated list

Code: Select all

CREATE FUNCTION [dbo].[TVF_ActivityRooms] (
	@ActivityID numeric(16, 0)
)
RETURNS TABLE
AS
RETURN

SELECT
/*Used in student timetables - ProMonitor, ProPortal, Moodle & student dashboard*/
	Value = 
		STUFF (
			(
				SELECT DISTINCT
					', ' + RM.r_reference
				FROM ulive.dbo.capd_roomregister RREG2
				INNER JOIN ulive.dbo.capd_room RM
					ON RM.r_id = RREG2.rr_room
				WHERE 
					RREG2.rr_activity = RREG.rr_activity
				ORDER BY ', ' + RM.r_reference FOR XML PATH(''),
				TYPE 
			).value('.','varchar(max)') ,1,2, '' 
		)
FROM ulive.dbo.capd_roomregister RREG
INNER JOIN ulive.dbo.capd_room RM
	ON RM.r_id = RREG.rr_room
WHERE
	RREG.rr_activity = @ActivityID
GROUP BY
	RREG.rr_activity