COGNOiSe.com - The IBM Cognos Community

IBM Cognos Analytics Platform => Cognos Analytics => Topic started by: orlando25 on 21 Apr 2025 06:05:44 PM

Title: Like Any Prompt
Post by: orlando25 on 21 Apr 2025 06:05:44 PM
I am using the below prompt in a report and I want to be able to have the % wildcard automatically concatenated around each word in the search criteria.  For example if a user wants to search for SMITH,JONES, I want the prompt to put in the % wildcard so it looks like this:  Search Criteria: %SMITH%,%JONES%

I was able to concatenate the % when just using LIKE but with LIKE ANY, I couldn't get it to work.

fieldname LIKE ANY (#csv( split(',',  toupper(prompt('SEARCH_CRITERIA', 'token'))))#)

The version of Cognos I am using is: IBM Cognos Analytics with Watson 11.2.4

Thank you
Title: Re: Like Any Prompt
Post by: dougp on 21 Apr 2025 06:33:49 PM
You say you got it to work with LIKE.  What expression did you use with LIKE?
Title: Re: Like Any Prompt
Post by: orlando25 on 22 Apr 2025 10:33:14 AM
This is what i used for LIKE:

fieldname LIKE UPPER('%'||(#sq(prompt('SEARCH_CRITERIA', 'token'))#)||'%')
Title: Re: Like Any Prompt
Post by: dougp on 23 Apr 2025 12:37:10 PM
I use SQL Server, so I can't try LIKE ANY, but will this work?

fieldname LIKE ANY (#csv(substitute('$', '%', substitute('^', '%', split(',',  toupper(prompt('SEARCH_CRITERIA', 'token'))))))#)
Get SEARCH_CRITERIA value.
Convert the value to upper case.
Split comma-delimited string into individual values.
Replace the beginning (0 characters) of each string with %.
Replace the ending (0 characters) of each string with %.
Join the individual strings into a comma-delimited list.

You may need to wrap the csv() function in sq()
Title: Re: Like Any Prompt
Post by: orlando25 on 24 Apr 2025 10:39:18 AM
dougp, thank you so much.  your suggestion worked perfectly!