Created
July 14, 2020 17:59
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- | |
-- 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