[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_AgeSept
Page 1 of 1

TVF_AgeSept

Posted: Thu Mar 02, 2017 10:41 pm
by robinwilson16
Returns the age of a learner on 31st Aug for the year specified

Code: Select all

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

SELECT
	Value = FLOOR ( DATEDIFF ( DAY, P.p_dob, CAST ( LEFT ( @Session, 4 ) + '-09-01' AS DATETIME2 ) ) / 365.23076923074 )
FROM ulive.dbo.capd_student S
INNER JOIN ulive.dbo.capd_person P
	ON P.p_id = S.s_id
WHERE
	S.s_studentreference = @StudentRef