Exit Script Examples: Difference between revisions

From QPR ProcessAnalyzer Wiki
Jump to navigation Jump to search
(403051)
 
No edit summary
Line 35: Line 35:
(SELECT 'RunScriptId', @ScriptToRun)   
(SELECT 'RunScriptId', @ScriptToRun)   
  --#Exit
  --#Exit
</pre>
The following example script stops the execution of the current script if the script has been last modified more than 600 seconds ago
<pre>
(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
</pre>
</pre>




[[Category:Examples]]
[[Category:Examples]]

Revision as of 06:47, 12 August 2016

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