TVF_AuditStudentApplication

The list of table valued functions used by Guildford College Reports and any anyone else wishes to share
Post Reply [phpBB Debug] PHP Warning: in file [ROOT]/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1266: count(): Parameter must be an array or an object that implements Countable
User avatar
robinwilson16
Site Admin
Posts: 185
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
[phpBB Debug] PHP Warning: in file [ROOT]/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1266: count(): Parameter must be an array or an object that implements Countable

TVF_AuditStudentApplication

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

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

Code: Select all

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

	SELECT TOP 1
		--Value = COALESCE ( SAD.sad_value, SA.sa_status ) --SAD.sad_value
		Value = COALESCE ( SAD.sad_value, 'NAP' ) --NAP = Not Yet Applied
	FROM ulive.dbo.capd_studentapplication SA
	LEFT JOIN ulive.dbo.CAPS_SYSTEM_AUDIT_TRAIL SAT --change the left join to inner join
		ON SAT.sat_id = SA.sa_id	
		AND SAT.SAT_END <= @DateChanged
	LEFT JOIN ulive.dbo.caps_system_audit_details SAD --change the left join to inner join
		ON SAD.sad_id = SAT.SAT_AUDIT
		AND SAD.sad_property = 'status'
	WHERE	
		SA.sa_id = @StudentApplicationID
	ORDER BY
		SAT.SAT_END DESC

Post Reply [phpBB Debug] PHP Warning: in file [ROOT]/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1266: count(): Parameter must be an array or an object that implements Countable
[phpBB Debug] PHP Warning: in file [ROOT]/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1266: count(): Parameter must be an array or an object that implements Countable
[phpBB Debug] PHP Warning: in file [ROOT]/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1266: count(): Parameter must be an array or an object that implements Countable

Who is online

Users browsing this forum: No registered users and 0 guests