TVF_AuditStudentEnrolment

The list of table valued functions used by Guildford College Reports and any anyone else wishes to share
Post Reply
User avatar
robinwilson16
Site Admin
Posts: 184
Joined: Sun Oct 16, 2016 6:46 pm
Forename: Robin
Surname: Wilson
College Name: FEA
Position: MIS Consultant
LinkedIn Profile: https://www.linkedin.com/in/robinwilson16

TVF_AuditStudentEnrolment

Post by robinwilson16 » Thu Mar 02, 2017 10:45 pm

Returns the status of an enrolment at a certain point in time. Useful for accurately reporting on the number of enrolments on a certain date. Use with caution on large queries as will show your query down - running for all enrolments here takes about 2.5mins

Code: Select all

CREATE FUNCTION [dbo].[TVF_AuditStudentEnrolment] (
	@Session VARCHAR(7), 
	@StudentEnrolmentID numeric(16, 0),
	@DateChanged DateTime
)
RETURNS TABLE
AS
RETURN 
	/*
	DECLARE @Session NVARCHAR(7) = '2015-16'
	DECLARE @StudentEnrolmentID numeric(16, 0) = 727000003893609
	DECLARE @Property VARCHAR(20) = 'status'
	DECLARE @DateChanged DateTime = '2016-06-01'
	*/
	--6

	SELECT TOP 1
		Value = SAD.sad_value --COALESCE ( SAD.sad_value, ME.e_status )
	FROM ulive.dbo.capd_moduleenrolment ME
	INNER JOIN ulive.dbo.CAPS_SYSTEM_AUDIT_TRAIL SAT --changed left to inner
		ON SAT.sat_id = ME.e_id	
		AND SAT.SAT_END <= @DateChanged
	INNER JOIN ulive.dbo.caps_system_audit_details SAD --changed left to inner
		ON SAD.sad_id = SAT.SAT_AUDIT
		AND SAD.sad_property = 'status'
	WHERE	
		ME.e_id	= @StudentEnrolmentID
	ORDER BY
		SAT.SAT_END DESC

Post Reply

Who is online

Users browsing this forum: No registered users and 2 guests