COGNOiSe.com - The IBM Cognos Community

IBM Cognos 10 Platform => Cognos 10 BI => Report Studio => Topic started by: keating101 on 06 Jun 2014 08:12:56 PM

Title: Substring Query
Post by: keating101 on 06 Jun 2014 08:12:56 PM
Hi Guys,

I am designing a report studio report.
There is a single data item which is essentially made up of "Department.CostElement".
For example CAFE.ELEC - Café been the department, ELEC (Electricity) been the cost element.

How do I write some code to split the two - so department and cost element are separate?
The problem is that the character length of department and cost element vary, so I cannot write a straight substring code.

Thanks in advance,
Shaun
Title: Re: Substring Query
Post by: navissar on 07 Jun 2014 02:24:09 PM
That's what the "position" function is for. It returns the first occurrence of a character, in your case, ".".
Consider the two following expressions:
substring ([Department.CostElement],1,position ('.',[Department.CostElement])-1)
That will substring from the first position to the position of the first period minus one. In your example, it would be from 1 for (5-1=)4 steps:"CAFE".
Now, this:
substring ([Department.CostElement],position ('.',[Department.CostElement])+1)
This will substring from the next character after the period and all the way through the string.

Title: Re: Substring Query
Post by: keating101 on 10 Jun 2014 12:35:38 AM
thanks - that worked.
Issue closed