COGNOiSe.com - The IBM Cognos Community

IBM Cognos 10 Platform => Cognos 10 BI => Report Studio => Topic started by: nsaxena on 23 Mar 2017 04:19:54 PM

Title: How to implememt regex feature in cognos report studio
Post by: nsaxena on 23 Mar 2017 04:19:54 PM
Hello All,

I have a string column from which i need to extract all columns containing 'XXX' AND 'YY' . These two can appear at any length of string but will always be together(i.e 3X will be together and 2 Y will b together).

Please suggest how to implement this.
Database is DB2
Title: Re: How to implememt regex feature in cognos report studio
Post by: Lynn on 24 Mar 2017 03:32:27 AM
Quote from: nsaxena on 23 Mar 2017 04:19:54 PM
Hello All,

I have a string column from which i need to extract all columns containing 'XXX' AND 'YY' . These two can appear at any length of string but will always be together(i.e 3X will be together and 2 Y will b together).

Please suggest how to implement this.
Database is DB2

Find out if your version of DB2 has support for regexp built-in functions.

https://www.ibm.com/support/knowledgecenter/en/ssw_ibm_i_71/db2/rbafzscaregexp_instr.htm

Also consider the locate or position function to identify if the column has the string or not.
Title: Re: How to implememt regex feature in cognos report studio
Post by: hespora on 24 Mar 2017 06:31:50 AM
If existence of those partial strings is all you're looking for, especially without any demands to the surroundings of the partial strings, you don't need regex for that.

if(
  (position('XXX',[string])>0) and (position('YY',[string])>0)
  )
then (1)
else (0)

and filter for 1
Title: Re: How to implememt regex feature in cognos report studio
Post by: Invisi on 27 Mar 2017 04:48:51 AM
There is also the function 'contains' that you can also use in query filters.