-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCREATE VIEW vwOrderedTerms.sql
55 lines (45 loc) · 1.03 KB
/
CREATE VIEW vwOrderedTerms.sql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
USE [Campus6]
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE VIEW [custom].[vwOrderedTerms]
AS
/***********************************************************************
Description:
Return a gapless list of terms in order. This may require customization for your institution's academic calendar.
Usage:
Revision History:
2023-10-02 Wyatt Best: Created
************************************************************************/
SELECT ACADEMIC_YEAR
,ACADEMIC_TERM
,RANK() OVER (
ORDER BY [START_DATE]
) [TermId] --Rank Terms
FROM (
SELECT --Get the earliest row for each ACADEMIC_TERM
ACADEMIC_YEAR
,ACADEMIC_TERM
,MIN(START_DATE) [START_DATE]
FROM ACADEMICCALENDAR
GROUP BY ACADEMIC_YEAR
,ACADEMIC_TERM
) [MinTerms]
/*
--Alternate example method
SELECT ACADEMIC_YEAR
,ACADEMIC_TERM
,RANK() OVER (
ORDER BY ACADEMIC_YEAR
,CAT.SORT_ORDER
) [TermId]
FROM ACADEMICCALENDAR ACAL
INNER JOIN CODE_ACATERM CAT
ON CAT.CODE_VALUE_KEY = ACAL.ACADEMIC_TERM
GROUP BY ACADEMIC_YEAR
,ACADEMIC_TERM
,CAT.SORT_ORDER
*/
GO