Page 1 of 1

SSRS_PROG

Posted: Mon Feb 20, 2017 6:05 pm
by robinwilson16
Lists programmes:

Code: Select all

CREATE FUNCTION [dbo].[SSRS_PROG] (
	@Session VARCHAR(7),
	@Fac VARCHAR(4),
	@Team VARCHAR(20)
)
RETURNS TABLE
AS
RETURN


/*DECLARE @Session VARCHAR(7) = '2015-16'
DECLARE @Fac VARCHAR(4) = 'CNEB'
DECLARE @Team VARCHAR(20) = 'BISM-BAF100'*/

SELECT
	Code = PRG.m_reference,
	Description = PRG.m_reference + ' - ' + PRG.m_name
FROM ulive.dbo.capd_module PRG
INNER JOIN ulive.dbo.capd_department FAC
	ON FAC.d_id = PRG.m_moduledept
INNER JOIN ulive.dbo.capd_section TEAM
	ON TEAM.s_id = PRG.m_modulesection
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_status IN ( 'R', 'P' )
	AND FAC.d_reference = COALESCE ( @Fac, FAC.d_reference )
	AND TEAM.s_reference = COALESCE ( @Team, TEAM.s_reference )
UNION ALL
SELECT
	Code = NULL,
	Description = '-- All Programmes --'