Advanced job flow control I want to create a job with two steps:
 1. Success - go to step two, failure - exit(f).
 2. Success - exit(s), failure - go to step one, but if this step fails more than once - exit(f).
Initial thought was to query some kind of job run id in step one, and if there are four (or more) rows for this id exit with failure, but there is no such thing as run id.
What is the best way to implement this logic?
You can create duplicates of steps 1 and 2 as steps 3 and 4, and set the following flow:


Success - go to step two, failure - exit(f).
Success - exit(s), failure - go to step three
Success - go to step four, failure - exit(f).
Success - exit(s), failure - exit(f).


But if you can instead wrap steps 1 and 2 in a stored procedure or ad hoc query that handles the retry logic without duplication, then your solution will be much more understandable and maintenance-safe.