extract data expression
extract data expression
(OP)
I have 2 fields that I need to use in an expression:
Address Emerg_Contact
C/O John blank
C/O Sam null
C/O Jane Jones,Sam
Expression needed:
Emerg_Contact has data then take the data after the comma, add a space then take the data before the comma so Jones, Sam becomes Sam Jones, etc.
else if
emerg_contact is null or blank and Address has "C/O" then take the next character it finds after the "C/O" in the Address so the first record it would retrieve John. Note: I mentioned next character after the "C/O" becomes sometimes more than 1 space is entered after the "C/O"
Help is very appreciated.
Address Emerg_Contact
C/O John blank
C/O Sam null
C/O Jane Jones,Sam
Expression needed:
Emerg_Contact has data then take the data after the comma, add a space then take the data before the comma so Jones, Sam becomes Sam Jones, etc.
else if
emerg_contact is null or blank and Address has "C/O" then take the next character it finds after the "C/O" in the Address so the first record it would retrieve John. Note: I mentioned next character after the "C/O" becomes sometimes more than 1 space is entered after the "C/O"
Help is very appreciated.
RE: extract data expression
CODE
ADDRESS '['||EMERG_C
---------- ------------
C/O John [ ]
C/O Sam []
C/O Jane [Jones,Sam]
select case when ltrim(emerg_contact) is null then replace(Address,'C/O ')
when instr(emerg_contact,',')>0 then
substr(emerg_contact,instr(emerg_contact,',')+1) ||' '||
substr(emerg_contact,1,instr(emerg_contact,',')-1)
end result
from mytab;
RESULT
---------------------
John
Sam
Sam Jones
(aka Dave of Sandy, Utah, USA)
[I provide low-cost, remote Database Administration services: www.dasages.com]
"Beware of those that seek to protect you from harm or risk. The cost will be your freedoms and your liberty."
RE: extract data expression
RE: extract data expression
Prior to more rigorous testing, I propose adding one more line of code to my previous SQL. The way it was, nothing displays if the EMERG_CONTACT is neither blank, nor null, nor contains a comma. This code resolves that issue:
CODE
ADDRESS EMERG_CONT
---------- ----------
C/O John
C/O Sam
C/O Jane Jones,Sam
Whatever NYC Police
4 rows selected.
select case when ltrim(emerg_contact) is null then replace(Address,'C/O ')
when instr(emerg_contact,',')>0 then
substr(emerg_contact,instr(emerg_contact,',')+1) ||' '||
substr(emerg_contact,1,instr(emerg_contact,',')-1)
else emerg_contact
end result
from mytab;
RESULT
---------------------
John
Sam
Sam Jones
NYC Police
4 rows selected.
(aka Dave of Sandy, Utah, USA)
[I provide low-cost, remote Database Administration services: www.dasages.com]
"Beware of those that seek to protect you from harm or risk. The cost will be your freedoms and your liberty."
RE: extract data expression
(aka Dave of Sandy, Utah, USA)
[I provide low-cost, remote Database Administration services: www.dasages.com]
"Beware of those that seek to protect you from harm or risk. The cost will be your freedoms and your liberty."
RE: extract data expression
RE: extract data expression
I work downtown in SLC and live in Sandy. If you'd like to get together for our own Mini (Root)Beery Meet, then let me know via my signature, below.
Regards,
(aka Dave of Sandy, Utah, USA)
[I provide low-cost, remote Database Administration services: www.dasages.com]
"Beware of those that seek to protect you from harm or risk. The cost will be your freedoms and your liberty."