spGet_ATHLETICS_TEAM_PAGES

Parameters

Parameter Parameter Type Mode Description
@SeasonGuid uniqueidentifier IN

Definition

Copy


  CREATE PROCEDURE [dbo].[spGet_ATHLETICS_TEAM_PAGES] (@SeasonGuid UNIQUEIDENTIFIER = null)
  AS
  SET NOCOUNT ON

  DECLARE @EmptyGuid UNIQUEIDENTIFIER;
  SET @EmptyGuid = '00000000-0000-0000-0000-000000000000'

  DECLARE @temp TABLE(id INT);
  DECLARE @hasFilter BIT;
  SET @hasFilter = 0;

  IF @SeasonGuid = @EmptyGuid
  SET @SeasonGuid = null;

  BEGIN
  IF @SeasonGuid is not null
  BEGIN
  SET @hasFilter=1;
  INSERT INTO @temp(id)
  SELECT id FROM athletics_teams WHERE season=@SeasonGuid
  END
  END

  IF @hasFilter=0
  BEGIN
  INSERT INTO @temp(id) SELECT id FROM athletics_teams
  END

  SELECT DISTINCT at.ID TeamID,
  cte2.description season,
  cte4.description gender,
  COALESCE(cte3.description, '') division,
  COALESCE(cte1.description, '') sport,
  up.ID,
  up.UserPageTemplateId,
  up.ClientUserId,
  up.DisplayName,
  up.IsPublished,
  up.RealmContextId,
  upt.RealmType,
  upt.UserPageManagerID,
  upt.SitePageID
  FROM dbo.ATHLETICS_TEAMS at
  INNER JOIN (SELECT id FROM @temp GROUP BY id) t
  ON at.id = t.id
  LEFT JOIN dbo.sitecodetableentries cte1
  ON at.Sport = cte1.EntryGuid
  LEFT JOIN dbo.sitecodetableentries cte2
  ON at.Season = cte2.EntryGuid
  LEFT JOIN dbo.sitecodetableentries cte3
  ON at.division = cte3.EntryGuid
  LEFT JOIN dbo.sitecodetableentries cte4
  ON at.gender = cte4.EntryGuid
  INNER JOIN UserPages up
  ON up.RealmContextId = at.ID
  INNER JOIN UserPageManagerPageTemplates upt
  ON up.UserPageTemplateId = upt.ID
  WHERE upt.RealmType = 7 --Core.Data.PersonalPageData.EParentTypes.AthleticTeam

  AND up.IsPublished = 1
  ORDER BY season ASC, sport, division, gender