Print Page | Close Window

using 'Like' in Record selection formula issue

Printed From: Crystal Reports Book
Category: Crystal Reports 9 through 2020
Forum Name: Report Design
Forum Discription: The best way to design a report and problems you have encountered
URL: http://www.crystalreportsbook.com/forum/forum_posts.asp?TID=7656
Printed Date: 02 May 2024 at 7:47pm


Topic: using 'Like' in Record selection formula issue
Posted By: johnwsun
Subject: using 'Like' in Record selection formula issue
Date Posted: 10 Sep 2009 at 6:18pm
Hi All,
 
I have used 'like' in Report -> Selection Formula -> Record:
{HEADING_sub.HEAD} like {?subjects}
 
In the parameter prompt I gave instructions to user by typing
*Search Term*. ( with both * at the begining and the end of the Term). But the user doesn't like typing '*', they awlays want to type search term directly.
However typing * or not  typing * will return quite different set of records.
With * , there are more hits than without *.
Could anyone advise how to integrate * in the {HEADING_sub.HEAD} like {?subjects} above without typing * at the parameter prompt?
thanks in advance.
 
John



Replies:
Posted By: DBlank
Date Posted: 10 Sep 2009 at 7:32pm
Not at work so can't test this but I think
{HEADING_sub.HEAD} like ('*'+{?subjects}+'*')
should work
or you can just use an instring function
instr({HEADING_sub.HEAD},{?subjects},1)>0


Posted By: johnwsun
Date Posted: 10 Sep 2009 at 7:57pm
Hi DBlank,
 
the first option result in CR returning everything! I don't think it's searching the 'Term' typed in the parameter prompt.
the second option has an error "The array must be subscripted, e.g. Array"
Please advise again, thank you.
John


Posted By: DBlank
Date Posted: 11 Sep 2009 at 7:01am
You have the param set to allow multiple values?
That messes both of these up...
 
It gets into arrays which is not my forte but take a look at this...might help
http://www.crystalreportsbook.com/forum/forum_posts.asp?TID=7284 - http://www.crystalreportsbook.com/forum/forum_posts.asp?TID=7284
 


Posted By: johnwsun
Date Posted: 11 Sep 2009 at 11:24pm
Hi DBlank,
 
No, it does not take multiple values; it only allows to search a term at a time as instructed to the user, e.g. *nursing* in my original approach, tt results returns well but the user doesn't like to type *.
 
John


Posted By: DBlank
Date Posted: 12 Sep 2009 at 8:48am
Hey John,
I would double check that setting in the parameter.
I tested both processes and they both worked fine for me if the parmater was set with "Allow mutliple values"=False. When I changed that value to True both failed in the exact same way you described. The * process returned all not null records and the instr() choked on the array subscript.
If it is set to False, what are the other properties set to? Since my test of either approach worked I would think it would have to do with param properties being different than my test param.


Posted By: johnwsun
Date Posted: 12 Sep 2009 at 11:39pm
Hi DBlank,
 
thank you very much for pointing out...I was acutally doing 'allow multiple values ' but I gave up, and forgot to set that back to false. Yes, after using the first option you have advised, it works now.
However I will have to go back to check  the user's specification whether it requires multiple values or not. But searching multiple terms in differnt subject areas would not make sense in this report. For exmaple, searching 'nursing' only want to find nursing related information. When searching 'nursing' and 'engineering' would not make sense. If they require multiple values even in one subject area, I think I will refer to the example in the link you advised earlier.  Thank you very much for your help.
John


Posted By: johnwsun
Date Posted: 22 Sep 2009 at 5:15pm
Hi DBlank,
 
The user has to enter *term* in the parameter popup box, I'm afraid,  after I have tried to use CR's join function without sucess.:
{HEADING_sub.HEAD} = join({?subjects},  ', ' )
(without entering '*' with the searching terms.)
tthe formula  from the link above you advised works the same way as the join function except adding some filtering(I don't need to filter searching terms).
The searching must allow multiple terms so I will keep the setting as True for Allow multiple values.


Posted By: zach18
Date Posted: 15 Dec 2011 at 11:54am
Originally posted by johnwsun

Hi DBlank,
 

The user has to enter *term* in the parameter popup box, I'm afraid,  after I have tried to use CR's join function without sucess.:


{HEADING_sub.HEAD} = join({?subjects},  ', ' )

(without entering '*' with the searching terms.)

tthe formula  from the link above you advised works the same way as the join function except adding some filtering(I don't need to filter searching terms).

The searching must allow multiple terms so I will keep the setting as True for Allow multiple values.


I just created a formula that took the parameter and appended stars to both sides. then i used that formula in the select expert.

the formula looked like this
'*' + {?Parameter} + '*'

that worked for me.

-------------
Using Crystal Report 2008
www.zachtech.us



Print Page | Close Window