Skip to content

Instantly share code, notes, and snippets.

@forstie
Created July 14, 2020 17:59
Show Gist options
  • Save forstie/6ac74725ce5d14f28e78b3dd65231a92 to your computer and use it in GitHub Desktop.
Save forstie/6ac74725ce5d14f28e78b3dd65231a92 to your computer and use it in GitHub Desktop.
The SQL language is so robust, there's often more than one way to accomplish a task. In this Gist, I demonstrate how to extract the job user name from a qualified job name.
--
-- Author: Scott Forstie
-- Date : July 14, 2020
--
--
-- Question: How do I extract the Job User Name from a qualfied job name?
-- Answer : Use Locate_In_String with Substring
-- Bonus : Did you know that the QSYS2.JOB_NAME built-in global variable gives you the qualfied job-name of the current connection?
values qsys2.job_name,
substr(qsys2.job_name,
locate_in_string(qsys2.job_name, '/', 1, 1) + 1,
locate_in_string(qsys2.job_name, '/', 1, 2) -
(locate_in_string(qsys2.job_name, '/', 1, 1)+1));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment