COGNOiSe.com - The IBM Cognos Community

IBM Cognos 10 Platform => Cognos 10 BI => Report Studio => Topic started by: Todd129 on 24 Mar 2013 01:38:14 AM

Title: How to cut a string up to the space?
Post by: Todd129 on 24 Mar 2013 01:38:14 AM
Hi gurus:

I have a data item with string data that looks like: "firstname lastname"

How do I write a function at the report studio level to cut the string at the end of firstame, so that the data item now just looks like "firstname"

Many thanks!

Todd
Title: Re: How to cut a string up to the space?
Post by: adik on 24 Mar 2013 02:42:54 AM
create a data item with the following formula: substring([Name], 1, position(' ', [Name]) - 1)
Title: Re: How to cut a string up to the space?
Post by: Todd129 on 24 Mar 2013 11:55:54 PM
Thank you so much this worked perfectly  8)
Title: Re: How to cut a string up to the space?
Post by: Todd129 on 25 Mar 2013 12:39:40 AM
How is it possible to start substring from the second space character, not the first. See data example:

[DATA ITEM] = 'Billy Joe Bob'

For this guy, I want to cut the string at the second space, not the first. Any ideas?

All the best, Todd
Title: Re: How to cut a string up to the space?
Post by: adik on 25 Mar 2013 02:32:02 AM
substring(substring([Name], position(' ', [Name]), char_length([Name])), 1, position(' ', substring([Name], position(' ', [Name])) - 1)
Title: Re: How to cut a string up to the space?
Post by: shradha on 24 Jun 2019 12:42:27 PM
I want to substring Name in three names
[name] = Fname Mname Lname
Now, i want to create 3 columns out of it
like
[name1] = fname
[name2] = Mname
[name3] = Lname

Any help would be appreciated. My DB doesn't supposrt most of the functions. Subsrting is supported.

TIA
Title: Re: How to cut a string up to the space?
Post by: CognosPaul on 24 Jun 2019 08:14:19 PM
What database are you using? substring alone won't be sufficient, but most databases have a rich string function set.
Title: Re: How to cut a string up to the space?
Post by: shradha on 25 Jun 2019 12:37:16 AM
We are using IBM optim archival solution DB. The function set is very limited.
Title: Re: How to cut a string up to the space?
Post by: bus_pass_man on 25 Jun 2019 09:28:21 AM
If you have a fairly newish CA, if you know that you want to create two substrings based on the last occurrence of a space then use Occurrences_regex to determine the number of occurrences. 

Use that result in position_regex.

Put that into the starting point parameter of substring.

Except that can't handle a surname which itself has a space in it.  :(