|
| 1 | + |
| 2 | + |
| 3 | +/****** Object: StoredProcedure [dbo].[GetCurrentCoursesForCandidate_V2] Script Date: 22/07/2024 10:11:35 ******/ |
| 4 | +SET ANSI_NULLS ON |
| 5 | +GO |
| 6 | + |
| 7 | +SET QUOTED_IDENTIFIER ON |
| 8 | +GO |
| 9 | + |
| 10 | +-- ============================================= |
| 11 | +-- Author: Kevin Whittaker |
| 12 | +-- Create date: 16/12/2016 |
| 13 | +-- Description: Returns a list of active progress records for the candidate. |
| 14 | +-- Change 18/09/2018: Adds logic to exclude Removed courses from returned results. |
| 15 | +-- ============================================= |
| 16 | +ALTER PROCEDURE [dbo].[GetCurrentCoursesForCandidate_V2] |
| 17 | + -- Add the parameters for the stored procedure here |
| 18 | + @CandidateID int |
| 19 | +AS |
| 20 | +BEGIN |
| 21 | + -- SET NOCOUNT ON added to prevent extra result sets from |
| 22 | + -- interfering with SELECT statements. |
| 23 | + SET NOCOUNT ON; |
| 24 | + |
| 25 | + -- Insert statements for procedure here |
| 26 | + SELECT p.ProgressID, (CASE WHEN cu.CustomisationName <> '' THEN a.ApplicationName + ' - ' + cu.CustomisationName ELSE a.ApplicationName END) AS CourseName, p.CustomisationID, p.SubmittedTime AS LastAccessed, |
| 27 | + p.FirstSubmittedTime AS StartedDate, p.DiagnosticScore, p.PLLocked, cu.IsAssessed, dbo.CheckCustomisationSectionHasDiagnostic(p.CustomisationID, 0) |
| 28 | + AS HasDiagnostic, dbo.CheckCustomisationSectionHasLearning(p.CustomisationID, 0) AS HasLearning, |
| 29 | + COALESCE |
| 30 | + ((SELECT COUNT(Passes) AS Passes |
| 31 | + FROM (SELECT COUNT(AssessAttemptID) AS Passes |
| 32 | + FROM AssessAttempts AS aa |
| 33 | + WHERE (CandidateID = p.CandidateID) AND (CustomisationID = p.CustomisationID) AND (Status = 1) |
| 34 | + GROUP BY SectionNumber) AS derivedtbl_2), 0) AS Passes, |
| 35 | + (SELECT COUNT(SectionID) AS Sections |
| 36 | + FROM Sections AS s |
| 37 | + WHERE (ApplicationID = cu.ApplicationID)) AS Sections, p.CompleteByDate, CAST(CASE WHEN p.CompleteByDate IS NULL THEN 0 WHEN p.CompleteByDate < getDate() |
| 38 | + THEN 2 WHEN p.CompleteByDate < DATEADD(M, + 1, getDate()) THEN 1 ELSE 0 END AS INT) AS OverDue, p.EnrollmentMethodID, dbo.GetCohortGroupCustomisationID(p.ProgressID) AS GroupCustomisationID, p.SupervisorAdminID |
| 39 | + |
| 40 | +FROM Progress AS p INNER JOIN |
| 41 | + Customisations AS cu ON p.CustomisationID = cu.CustomisationID INNER JOIN |
| 42 | + Applications AS a ON cu.ApplicationID = a.ApplicationID INNER JOIN |
| 43 | + CentreApplications AS ca ON ca.ApplicationID = a.ApplicationID AND ca.CentreID = cu.CentreID |
| 44 | +WHERE (p.Completed IS NULL) AND (p.RemovedDate IS NULL) AND (p.CandidateID = @CandidateID)AND (cu.CustomisationName <> 'ESR') AND (a.ArchivedDate IS NULL) AND(cu.Active = 1) AND |
| 45 | +((p.SubmittedTime > DATEADD(M, -6, getDate()) OR (EnrollmentMethodID <> 1)) OR NOT (p.CompleteByDate IS NULL) AND NOT |
| 46 | +(p.SubmittedTime < DATEADD(MONTH, -6, GETDATE()) AND (p.EnrollmentMethodID = 1) AND (p.CompleteByDate < GETDATE()))) |
| 47 | +ORDER BY p.SubmittedTime Desc |
| 48 | +END |
| 49 | +GO |
0 commit comments