COGNOiSe.com - The IBM Cognos Community

IBM Cognos 10 Platform => Cognos 10 BI => Report Studio => Topic started by: cenario on 15 Apr 2020 03:43:01 AM

Title: Matching square brackets
Post by: cenario on 15 Apr 2020 03:43:01 AM
I'm trying to construct an expression to match a string with a format like this for example : "[00]"

My expression is:
IF (<variable> LIKE '%[__]%') THEN ('TRUE') ELSE ('FALSE')

However this always returns "False". Idk why but it has to do with the square brackets..

How do you type in the square brackets in cognos?

Thanks

Edit;
I noticed that if i use "<variable> LIKE '__]%'" then cognos recognizes the string.
So, the problem is on the first square bracket.. Does it need an escape character perhaps?
Title: Re: Matching square brackets
Post by: bus_pass_man on 15 Apr 2020 06:05:47 AM
How many underscores are you using?  Are there values which have the square brackets separated by exactly those number of characters? Would a '%[%]%' be more appropriate?

It works for me.

I created a calculation  which looks for this pattern and then substitute a string where the opening and closing square brackets are used.

(COUNTRY_EN  like '%t___i%') There are 3 underscores  This will return Australia and substitute  Aus[ral]a

I then created a filter similar to this

C_Country_En   like '%[___]%' 
as you can see, it finds Aus[ral]a


'%t___i%' (3 underscores) will find Australia.
'%t_i%' (1 underscore) will find Austria but not Australia

'%t%i%' will find both Austria and Australia
Title: Re: Matching square brackets
Post by: cenario on 15 Apr 2020 06:11:57 AM
I already tried '%[%]%' and still no results..

However if i do '%]%' then i have my expected results.

Which leads me to think -> Cognos isn't recognizing the first open bracket.

I think i'm going crazy because the string i'm searching for is "[51]". There's no reason for Cognos not recognize the first bracket.. But somehow it doesn't..

Thanks anyway

edit. typo

edit2. I'm officially losing my mind.

'%[51]%' finds the string, but '%[%]%' does not.
Title: Re: Matching square brackets
Post by: bus_pass_man on 15 Apr 2020 07:58:52 AM
It works for me.
Title: Re: Matching square brackets
Post by: bus_pass_man on 15 Apr 2020 07:59:40 AM
You can't put more than one file in a post so I had to add this here.
Title: Re: Matching square brackets
Post by: MFGF on 15 Apr 2020 08:43:58 AM
Good work sir!!

I'm wondering if this has anything to do with the underlying data source and reserved characters? It seems strange that it works for one person but not another.

Since this is a report, I'd also be looking closely at the SQL that gets generated, to see if the filter is being passed to the data source, and exactly how it is being formed if so.

Good luck!

MF.