This was an interesting problem, so I thought I'd share the solution.I needed to find a way in to identify the run ID of the previous run of a running task. I didn't find a way to do this using pure AE scripting, but I did come up with an SQL query that does the trick. This is for Oracle.
SELECT Prev_AH_Idnr from
(SELECT AH_Idnr, lead(aH_Idnr,1,0) OVER (ORDER BY AH_TIMESTAMP1 DESC) AS Prev_AH_Idnr
WHERE AH_Name = (SELECT AH_Name FROM AH WHERE AH_Idnr = ?))
WHERE AH_Idnr = ?
Both bind parameters should be set to the same thing: the run ID of the current task. If you use this in an SQLI, you can just insert &$RUNID# in both bind parameter values. Enjoy.