Skip to content

Commit bf35ff2

Browse files
committed
Removed restriction on VARCHAR(500) which sometimes failed
1 parent e2cb597 commit bf35ff2

File tree

1 file changed

+41
-13
lines changed

1 file changed

+41
-13
lines changed

Direct_Framework/Functions/omd.GetPreviousModuleInstanceDetails.sql

Lines changed: 41 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,22 +5,50 @@ CREATE FUNCTION [omd].[GetPreviousModuleInstanceDetails]
55
)
66
RETURNS TABLE AS
77

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+
*******************************************************************************/
1240

1341
RETURN
1442
(
1543
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]
2452
FROM
2553
(
2654
(
@@ -73,7 +101,7 @@ RETURN
73101
)
74102
,1,1,''
75103
)
76-
+ ')' as varchar(500)
104+
+ ')' AS VARCHAR(MAX)
77105
)
78106
) AS [LastModuleInstanceIDList]
79107

0 commit comments

Comments
 (0)