TVF_LearnerMainStudentApp

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_LearnerMainStudentApp

Post by robinwilson16 » Thu Mar 02, 2017 11:17 pm

Returns a learner's main student application record
Will always return a single line for each learner, useful for learner lists including main application information

Code: Select all

CREATE FUNCTION [dbo].[TVF_LearnerMainStudentApp] (@Session VARCHAR(10), @StudentRef VARCHAR(20)) RETURNS TABLE
AS
RETURN 

	SELECT TOP 1
		Value = SA.sa_id
	FROM ulive.dbo.capd_module PRG
	INNER JOIN ulive.dbo.capd_moduleapplication MAP
		ON MAP.ma_module = PRG.m_id
	INNER JOIN ulive.dbo.capd_studentapplication SA
		ON SA.sa_id = MAP.ma_studentapplication
	INNER JOIN ulive.dbo.capd_offering LNKPQ 
		ON LNKPQ.o_source = PRG.m_id
	INNER JOIN ulive.dbo.capd_module Q
		ON Q.m_id = LNKPQ.o_destination
	INNER JOIN ulive.dbo.capd_offering LNKQY 
		ON LNKQY.o_source = LNKPQ.o_destination
	INNER JOIN ulive.dbo.capd_moduleisr ISRY
		ON ISRY.mi_id = LNKQY.o_destination
	INNER JOIN ulive.dbo.capd_student S
		ON S.s_id = SA.sa_student
	INNER JOIN ulive.dbo.caps_valid_codes STA
		ON STA.vc_code = SA.sa_status
		AND STA.vc_domain = 'applicstatus'
	WHERE
		PRG.m_type = 'P'
		AND PRG.m_start <= LEFT ( @Session, 2 ) + RIGHT ( @Session, 2 ) + '-07-31'
		AND PRG.m_end >= LEFT ( @Session, 4 ) + '-08-01'​​
		AND PRG.m_start >= LEFT ( @Session, 4 ) + '-08-01'​​ -- Limit to programmes starting this year
		AND S.s_studentreference = @StudentRef
	ORDER BY
		CASE 
			WHEN STA.vc_ref = 'WDN' THEN 2 
			WHEN STA.vc_ref = 'TRF' THEN 3
			ELSE 1
		END ASC,--App Status
		CASE WHEN Q.m_programmearea = 'CA' THEN 1 ELSE 2 END ASC,--AimType
		CASE WHEN ISRY.mi_ilraimtype = '2' THEN '4.5' ELSE ISRY.mi_ilraimtype END DESC,--AimType -Moved here as not always filled in correctly
		COALESCE ( ISRY.mi_ilrplanlearnhours, 0 ) + COALESCE ( ISRY.mi_ilrplaneephours, 0 ) DESC,--Hours
		PRG.m_start ASC --Prog Start Date

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 1 guest