@@ -5,22 +5,50 @@ CREATE FUNCTION [omd].[GetPreviousModuleInstanceDetails]
5
5
)
6
6
RETURNS TABLE AS
7
7
8
- -- =============================================
9
- -- Function: GetPreviousModuleInstanceDetails
10
- -- Description: TODO: tba...
11
- -- =============================================
8
+ /* ******************************************************************************
9
+ * [omd].[GetPreviousModuleInstanceDetails]
10
+ *******************************************************************************
11
+ *
12
+ * https://github.com/data-solution-automation-engine/DIRECT
13
+ *
14
+ * DIRECT model v2.0
15
+ *
16
+ *
17
+ * Purpose: Returns details about the most recent completed execution of a specified module within a specific batch context.
18
+ * If no such instance exists, a default placeholder value is returned.
19
+ * This information can be used for determining module execution eligibility.
20
+ * The function retrieves the latest completed module instance based on the execution status and batch context.
21
+ *
22
+ * Inputs:
23
+ * - @ModuleId (INT): The ID of the module for which execution details are requested.
24
+ * - @BatchId (INT): The ID of the batch in which the module was executed. A value of 0 indicates standalone (non-batch) execution.
25
+ *
26
+ * Outputs:
27
+ * A single-row table containing the following fields:
28
+ * - LastBatchInstanceID: ID of the most recent batch instance.
29
+ * - LastModuleInstanceID: ID of the most recent module instance.
30
+ * - LastStartTimestamp: Start time of the last module execution.
31
+ * - LastEndTimestamp: End time of the last module execution.
32
+ * - LastExecutionStatus: Execution status code of the last module run.
33
+ * - LastNextExecutionFlag: Indicator suggesting the next action (e.g., 'Proceed').
34
+ * - LastModuleInstanceIDList: Comma-separated list of relevant module instance IDs after the last successful run.
35
+ * - ActiveIndicator: Flag indicating whether the module is active (ACTIVE_INDICATOR from the MODULE table).
36
+ *
37
+ * Usage:
38
+ *
39
+ *******************************************************************************/
12
40
13
41
RETURN
14
42
(
15
43
SELECT TOP 1
16
- ISNULL(MAX (LastBatchInstanceID),- 1 ) AS [LastBatchInstanceID]
17
- ,ISNULL(MAX (LastModuleInstanceID),- 1 ) AS [LastModuleInstanceID]
18
- ,ISNULL(MAX (LastStartTimestamp),' 1900-01-01' ) AS [LastStartTimestamp]
19
- ,MAX (LastEndTimestamp) AS [LastEndTimestamp]
20
- ,ISNULL(MAX (LastExecutionStatus),' I' ) AS [LastExecutionStatus]
21
- ,ISNULL(MAX (LastNextRunStatusCode),' Proceed' ) AS [LastNextExecutionFlag]
22
- ,ISNULL(MAX (LastModuleInstanceIDList),' -1' ) AS [LastModuleInstanceIDList]
23
- ,(SELECT ACTIVE_INDICATOR FROM [omd].[MODULE] WHERE MODULE_ID = @ModuleId) AS ActiveIndicator
44
+ ISNULL(MAX (LastBatchInstanceID),- 1 ) AS [LastBatchInstanceID]
45
+ ,ISNULL(MAX (LastModuleInstanceID),- 1 ) AS [LastModuleInstanceID]
46
+ ,ISNULL(MAX (LastStartTimestamp),' 1900-01-01' ) AS [LastStartTimestamp]
47
+ ,MAX (LastEndTimestamp) AS [LastEndTimestamp]
48
+ ,ISNULL(MAX (LastExecutionStatus),' I' ) AS [LastExecutionStatus]
49
+ ,ISNULL(MAX (LastNextRunStatusCode),' Proceed' ) AS [LastNextExecutionFlag]
50
+ ,ISNULL(MAX (LastModuleInstanceIDList),' -1' ) AS [LastModuleInstanceIDList]
51
+ ,(SELECT ACTIVE_INDICATOR FROM [omd].[MODULE] WHERE MODULE_ID = @ModuleId) AS [ ActiveIndicator]
24
52
FROM
25
53
(
26
54
(
@@ -73,7 +101,7 @@ RETURN
73
101
)
74
102
,1 ,1 ,' '
75
103
)
76
- + ' )' as varchar ( 500 )
104
+ + ' )' AS VARCHAR (MAX )
77
105
)
78
106
) AS [LastModuleInstanceIDList]
79
107
0 commit comments