COGNOiSe.com - The IBM Cognos Community

IBM Cognos Analytics Platform => Cognos Analytics => Reporting => Topic started by: andregomes on 25 May 2017 01:33:58 PM

Title: Last positon in string REPORT STUDIO
Post by: andregomes on 25 May 2017 01:33:58 PM
Good afternoon people,
Sorry for my english first and I have a problem.

I need to get the last occurrence of a char in a string and make the substring from that position.
For example

I have some strings
'Www.google.com'
'Www.bbc.com'
'Www.university.edu'
I need to return now
'com'
'com'
'Edu'
how to make ?



I tried using the Position function in the report studio but the '.' Is in different positions, so I need to get the last occurrence of '.' And use the substring from that point.

Thank you
Title: Re: Last positon in string REPORT STUDIO
Post by: Niranjan81 on 25 May 2017 02:17:20 PM
I would do a string reverse , calculate upto the char that's needed using substr( , . )
and then reverse the final output using strrev again.
Title: Re: Last positon in string REPORT STUDIO
Post by: andregomes on 25 May 2017 02:19:32 PM
Thank you,
But I do not know how to do this reverse calculation.

Position ('.'; [Field]) returns me the first position, but how to return the last?
Title: Re: Last positon in string REPORT STUDIO
Post by: Niranjan81 on 25 May 2017 02:32:00 PM
which db are you using ?
If you want to use cognos function - its REVERSE.

Thanks
NC
Title: Re: Last positon in string REPORT STUDIO
Post by: Niranjan81 on 25 May 2017 02:33:54 PM
https://www.ibm.com/support/knowledgecenter/SSEP7J_10.1.1/com.ibm.swg.ba.cognos.ug_cogtr.10.1.1.doc/c_textfunctions_tr.html
Title: Re: Last positon in string REPORT STUDIO
Post by: andregomes on 25 May 2017 03:29:22 PM
ITS WORKS.... thank you so much.

you save my day.
Title: Re: Last positon in string REPORT STUDIO
Post by: Niranjan81 on 26 May 2017 01:17:30 PM
Glad its working.
Thanks,
NC