Avatar of DeonM
DeonM

asked on 

Crystal Report, select records by keywords

Using the "Select Expert" option in crystal reports to filter records, how can i do this to filter by keywords or any characters? I see there is an option to select the "is like" condition but I haven't had any successful attempts using this feature.

So for example i want to filter records by "Vehicle Description" which will be passed through as a parameter from the front end entered by the client, so this value could be anything.

I tried this for example: {Vehicles.Description} = {?DescParameter}. where the parameter could be any part of the the model description of a vehicle.

Thanks
Crystal Reports

Avatar of undefined
Last Comment
DeonM
Avatar of dougvarga
dougvarga
Flag of United States of America image

Try this as your selection formula:
 {Vehicles.Description} = "*"+Trim({?DescParameter})+"*"

Open in new window

Avatar of dougvarga
dougvarga
Flag of United States of America image

scratch that:  Should be:
{Vehicles.Description} like "*"+Trim({?DescParameter})+"*"

Open in new window

Avatar of DeonM
DeonM

ASKER

I receive and error in the formula workshop on the parameter name which states: "This array must be subscripted. For example: Array [i]"

The parameter is a string which may contain multiple values but will never have more than one.
Avatar of dougvarga
dougvarga
Flag of United States of America image

Didn't realize {?descParameter} allowed multiple values.  You won't be able to use the Trim.

Try this:



{Vehicles.Description} like "*"+{?DescParameter}+"*"

Open in new window

Avatar of Mike McCracken
I believe if you are using multiple values you may have to use the full name and not use wildcards.

mlmcc
Avatar of James0628
James0628

You can use LIKE with a multi-value parameter, as long as it's multiple single values and does not allow ranges.  But the values you're testing have to include wildcards (* or ?), otherwise LIKE will give you the same results as =.  For example, {table.field} LIKE "ab" will only match "ab", while {table.field} LIKE "ab*" will match any string that starts with "ab".  The simplest way to get wildcards in your parameter values is to have the users enter them (you could put a message about them in the parameter prompt).  Otherwise, you could add them yourself (eg. loop through the parameter values and add "*" to the beginning and end of each value).

 However, you should also be aware that LIKE is case sensitive, so, for example, {table.field} LIKE "ab*" will be false if the field is "Ab".

 If you want to do a case-insensitive comparison, you'll need to check each value in your parameter separately (eg. using StrCmp, which has an option to do a case-insensitive comparison).

 James
Avatar of DeonM
DeonM

ASKER

Thanks for the posts, I will put them to use as soon as i get answers to my other question. At the moment my reports don't work due to that problem discussed in my other question.
ASKER CERTIFIED SOLUTION
Avatar of dougvarga
dougvarga
Flag of United States of America image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Avatar of dougvarga
dougvarga
Flag of United States of America image

Just want to clarify - the formula above is the 2nd approach that James mentioned in his post.  (Looping through the parameters and adding the "*").  Was trying it for myself and thought I'd share the code....
Avatar of DeonM
DeonM

ASKER

Thank you for the great posts and of course for the code you shared :)
Crystal Reports
Crystal Reports

Crystal Reports is a business intelligence application from SAP SE. It is used to graphically design data connections and report layouts from a wide range of data sources including Excel spreadsheets, Oracle, SQL Server databases and Access databases, BusinessObjects Enterprise business views, and local file-system information. Report designers can place fields from these sources on the report design surface, and can also deploy them in custom formulas (using either BASIC or Crystal's own syntax), which are then placed on the design surface. Crystal Reports also supports subreports, graphing, and a limited amount of GIS functionality.

36K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo