TVF_SessionCodeYearlyMapping

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

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

Given a year/session and the number of years (can be negative or positive) returns the year/session the specified number of years behind or ahead.
Useful for comparing two years of data

Code: Select all

CREATE FUNCTION [dbo].[TVF_SessionCodeYearlyMapping] (
	@Session VARCHAR(7), 
	@Years int
)
RETURNS TABLE
AS
RETURN

	SELECT
		Value = 
			CAST ( CAST ( LEFT ( @Session, 4 ) AS int ) + @Years AS VARCHAR(4) ) 
			+ '-' 
			+ CAST ( CAST ( RIGHT ( @Session, 2 ) AS int ) + @Years AS VARCHAR(4) )

Post Reply

Who is online

Users browsing this forum: No registered users and 2 guests