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

SSRS_TEAM_COST_CENTRE_MULTI

Posted: Mon Feb 20, 2017 6:02 pm
by robinwilson16
Lists teams/cost centres for multi-select:

Code: Select all

CREATE FUNCTION [dbo].[SSRS_TEAM_COST_CENTRE_MULTI] (
	@Session VARCHAR(7),
	@Fac VARCHAR(MAX)
)
RETURNS TABLE
AS
RETURN
--DECLARE @Session VARCHAR(7) = '2015-16'
--DECLARE @Fac VARCHAR(4) = 'CNEB'

SELECT
	 Code = '-1',
     Description = '-- All Teams / Cost Centres --' 

UNION ALL

SELECT
	Code = TEAM.s_reference,
	Description = FAC.d_reference + ' - ' + TEAM.s_reference + ' - ' + TEAM.s_name
FROM ulive.dbo.capd_section TEAM
INNER JOIN ulive.dbo.capd_department FAC
	ON FAC.d_id = TEAM.s_department
LEFT JOIN GC.dbo.TeamTitles TT
	ON TT.TeamCode = LEFT(TEAM.s_reference,4)
INNER JOIN (
	SELECT DISTINCT
		TeamID = PRG.m_modulesection
	FROM ulive.dbo.capd_module PRG
	INNER JOIN ulive.dbo.capd_department FAC
		ON FAC.d_id = PRG.m_moduledept
	WHERE
		PRG.m_start <= LEFT ( @Session, 2 ) + RIGHT ( @Session, 2 ) + '-07-31'
		AND PRG.m_end >= LEFT ( @Session, 4 ) + '-08-01'​​
		AND PRG.m_type = 'P'
		AND PRG.m_status IN ( 'R', 'P' )
		AND 
			CASE
				WHEN @Fac LIKE '%-1%' THEN 1
				ELSE 
					CASE
						WHEN ', ' + @Fac + ',' LIKE '%, ' + FAC.d_reference + ',%' THEN 1
						ELSE 0
					END
			END = 1
) CRS ON CRS.TeamID = TEAM.s_id
WHERE
	COALESCE ( FAC.d_start, LEFT ( @Session, 2 ) + RIGHT ( @Session, 2 ) + '-07-31' ) <= LEFT ( @Session, 2 ) + RIGHT ( @Session, 2 ) + '-07-31'
	AND COALESCE ( FAC.d_end, LEFT ( @Session, 4 ) + '-08-01'​​ ) >= LEFT ( @Session, 4 ) + '-08-01'​​
	AND COALESCE ( TEAM.s_start, LEFT ( @Session, 2 ) + RIGHT ( @Session, 2 ) + '-07-31' ) <= LEFT ( @Session, 2 ) + RIGHT ( @Session, 2 ) + '-07-31'
	AND COALESCE ( TEAM.s_end, LEFT ( @Session, 4 ) + '-08-01'​​ ) >= LEFT ( @Session, 4 ) + '-08-01'​​