[phpBB Debug] PHP Warning: in file [ROOT]/phpbb/session.php on line 580: sizeof(): Parameter must be an array or an object that implements Countable
[phpBB Debug] PHP Warning: in file [ROOT]/phpbb/session.php on line 636: sizeof(): Parameter must be an array or an object that implements Countable
Unofficial UNIT-e Forum • TVF_RegisterRooms
Page 1 of 1

TVF_RegisterRooms

Posted: Thu Mar 02, 2017 11:47 pm
by robinwilson16
Returns all the rooms attached to a register as a single comma separated list

Code: Select all

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

SELECT
	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_register = RREG.rr_register
				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_register = @RegisterID
GROUP BY
	RREG.rr_register