TVF_AgeSept

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: 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

TVF_AgeSept

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

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

Post Reply

Who is online

Users browsing this forum: No registered users and 2 guests