TVF_AgeEnrStart

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_AgeEnrStart

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

Returns the age of a learner when the programme started

Code: Select all

CREATE FUNCTION [dbo].[TVF_AgeEnrStart] (
	@Session VARCHAR(7),
	@ProgEnrID numeric(16,0), 
	@StudentRef VARCHAR(20)
)
RETURNS TABLE
AS
RETURN

	
	--DECLARE @StudentRef varchar(20) = '16001195'

	SELECT DISTINCT
		Value = FLOOR ( DATEDIFF ( DAY, P.p_dob, MEP.e_start ) / 365.23076923074 )
	FROM ulive.dbo.capd_module PRG
	INNER JOIN ulive.dbo.capd_moduleenrolment MEP
		ON MEP.e_module = PRG.m_id
	INNER JOIN ulive.dbo.capd_student S
		ON S.s_id = MEP.e_student
	INNER JOIN ulive.dbo.capd_person P
		ON P.p_id = S.s_id
	WHERE
		PRG.m_type = 'P'
		AND PRG.m_start <= CAST(LEFT ( @Session, 2 ) + RIGHT ( @Session, 2 ) + '-07-31' AS DATE)
		AND PRG.m_end >= CAST(LEFT ( @Session, 4 ) + '-08-01'​​ AS DATE)
		AND S.s_studentreference = @StudentRef
		AND MEP.e_id = @ProgEnrID

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