Exit Script Examples: Difference between revisions

From QPR ProcessAnalyzer Wiki
Jump to navigation Jump to search
No edit summary
No edit summary
 
(One intermediate revision by the same user not shown)
Line 1: Line 1:
This page contains script examples for the [[Supported_QPR_ProcessAnalyzer_Commands_in_Scripts#--.23Exit|Exit]] script command.
This page contains script examples for the [[SQL Scripting Commands#--.23Exit|Exit]] script command.
<br/>
<br/>
<br/>
<br/>

Latest revision as of 20:49, 25 October 2021

This page contains script examples for the Exit script command.

The Exit command can in effect be used to "call" a script, i.e. run a different script and then return to continue the current script.

(SELECT 'Exit', '0') UNION ALL 
(SELECT 'RunScriptId', '12')   
--#Exit 

The Exit command can also be used to "goto" a script, i.e. stop the execution of the current script and run a different script.

(SELECT 'Exit', '1') UNION ALL  
(SELECT 'RunScriptId', '12')  
--#Exit 

The following example stops the script execution, gives a message, and runs a script with Id 12.

(SELECT 'Exit', '1') UNION ALL
(SELECT 'MessageText', 'Data from SAP not valid. Script execution will be terminated. Check source data. Running script Id 12.') UNION ALL
(SELECT 'RunScriptId', '12')
--#Exit

The following example script fragment checks if the previous ProcessAnalyzer command had any exceptions, and if it did, will goto script with Id 2. If the previous command didn't have any exceptions, the script execution is stopped.

DECLARE @ScriptToRun VARCHAR(10)

IF @_ExceptionOccurred = 1 
 SET @ScriptToRun = '2' 
 ELSE SET @ScriptToRun  = ''

(SELECT 'Exit', '1') UNION ALL  
(SELECT 'RunScriptId', @ScriptToRun)  
 --#Exit

The following example script stops the execution of the current script if the script has been last modified more than 600 seconds ago

(SELECT 'AnalysisType', '24') UNION ALL
(SELECT 'TargetTable', '#ScriptAnalysis')
--#GetAnalysis

(SELECT 'Exit', IIF((DATEDIFF(ss,[Last Modified On],GETDATE()) > 600),1,0) FROM #ScriptAnalysis where [Id] = @_ScriptId)
--#Exit