What’s the correct syntax of using substring function in the universe.
Need to convert a sting to something like this,
Example: Smith,John --> John Smith
Used the following function to create a object to grab the last name but its not parsing .
substring((DB2.Site.Manager) ,Pos((DB2.Site.Manager), ", ")+1 ,Length(DB2.Site.Manager))
However, I think that the problem in your formula is not the SUBSTR() function but the POS() function. POS() is a BO report level function. Very likely, it’s not a function available in DB2 database. You might use LOCATE() function instead:
SUBSTR((DB2.SITE.SITE_MANAGER_FULLNAME_TYPE1),1,LOCATE(’ ',(DB2.SITE.SITE_MANAGER_FULLNAME_TYPE1))-1)
The code parses correctly but when run it in the report gives error
saying the second or third aguments in substring function is out of range.
While I dont know the first thing about DB2, we do have an object in one of our Universes doing exactly the same thing on an Oracle database… I cant imagine that the syntax would be that different…
case when instr(AGENT_NAME,’, ‘) <>0 then substr(AGENT_NAME,(instr(AGENT_NAME,’,’)+2))||’ ‘||substr(AGENT_NAME,1,(instr(AGENT_NAME,’,’)-1))
when instr(AGENT_NAME,’,’) <>0 then substr(AGENT_NAME,(instr(AGENT_NAME,’,’)+1))||’ ‘||substr(AGENT_NAME,1,(instr(AGENT_NAME,’,’)-1))
else AGENT_NAME end
SELECT SUBSTR('Smith,John', INSTR('Smith,John',',')+1 , LENGTH('Smith,John')) || ' '|| SUBSTR('Smith,John', 1, INSTR('Smith,John',',')-1) AS NAME FROM DUAL
The issue is with string in the field, Because its displays sometime
(Smith John) or (Smith , John) in the table and I need to change that to display John Smith in the report.
Tried to use a case function but that didn’t work.
Would able to split the string and get the second section with substr(). But not working to get the first section because the string separate by either by sapce or coma .
Have any idea how to create object in the universe to avoid this issue?.
Appreciate any help
Thanks!!
Try replacing a comma with a space first. Then the names will be separated by 1 or more spaces but there will be no comma. Then using the above logic find the first occurrence of a space in a string and make the split of the string from there. Maybe at the end, you will need to use also TRIM() function (or its equivalent in DB2) to get rid of the trailing spaces.