Solved

Crystal Reports 2008 - Finding an array value in a string

Posted on 2010-09-10
14
969 Views
Last Modified: 2012-05-10
I've got a report with an optional parameter for Lot # (ex. n498p).  The field in the database is a string field that could contain multiple lot numbers (ex. "n498p, n502p").  For the report parameter, I want to use multiple values so they can search for 1 or more lot numbers.  In the record selection formula, how do I loop through that array to check each value and see if it show up "in" the string field?

~bruno71
0
Comment
Question by:bruno71
  • 4
  • 4
  • 4
  • +1
14 Comments
 
LVL 26

Expert Comment

by:Kurt Reinhardt
ID: 33648927
You don't.

You can simply use {table.field} = {?multiplevalueparameter}

Since you're using an optional parameter, however, you do need to account for the possibility that the parameter might be empty.  As such, use the following:

If
  HasValue({?multiplevalueparameter})
Then
  {table.field} = {?multiplevalueparameter}
Else
  True

~Kurt
0
 
LVL 26

Expert Comment

by:Kurt Reinhardt
ID: 33648951
Never mind, I read it too quickly and missed the part about the actual database field.  The rest still stands, but I'll need to work something else out.

~Kurt
0
 
LVL 26

Expert Comment

by:Kurt Reinhardt
ID: 33649554
The following code will work IF you input wildcards into your parameter entry...

If
  HasValue({?multiplevalueparameter})
Then
  {table.field} Like {?multiplevalueparameter}
Else
  True

Please note, that while this will work, it won't be particularly efficient, since using LIKE will force a full table scan, but at least it will be processed on the database as opposed to the client.

~Kurt

0
 
LVL 5

Expert Comment

by:Priya Perumpilavil
ID: 33660756
create a stored procedure like this from your table

declare @str as varchar(1000)
//set @str = '#E00001#, #E00002#, #E00003#'
select * from ppemp where
@str  Like '%#' + empno_k + '#%'  


and pass the parameter as  
 '#E00001#, #E00002#, #E00003#'
you will get the result




0
 
LVL 5

Expert Comment

by:Priya Perumpilavil
ID: 33660764
crystal report has to made with the stored procedure
0
 
LVL 26

Expert Comment

by:Kurt Reinhardt
ID: 33661035
It doesn't have to be made with a stored procedure.

~Kurt
0
 

Author Comment

by:bruno71
ID: 33662408
Kurt,

It's kind of working.  I'm using LIKE with the wildcards...

(not HasValue({?Block Lot #}) OR {GW_SCRAP.BlockLotNum} like "%" + {?Block Lot #} + "%")

...but it's not finding any fields that contain the value, only fields that are equal to it.  For example, it will find a record with "n498p", but not "n498p, n500p"

Mike
0
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 
LVL 100

Expert Comment

by:mlmcc
ID: 34277642
Do you still need help with this?

mlmcc
0
 

Author Comment

by:bruno71
ID: 34282987
Yes...I never quite got it to work just right.  I have a report parameter that let's them input multiple values.  However, the report is only finding records EQUAL to the value, not CONTAINING the value.

~bruno71
0
 
LVL 100

Expert Comment

by:mlmcc
ID: 34283739
So you have a field that may contain say
   "n498p, n502p"

and a parameter that may contain
   "n498p"  or ""  or "n498p, n503p"

Is that correct?

mlmcc
0
 

Author Comment

by:bruno71
ID: 34283959
I may have the following fields...
1. "n498p"
2. "n498p, n502p"
3. "n502p"

For the parameter (which allows multiple values), I enter "n498p" and "n502p" (enter one...click the arrow to add it to the list...enter the second...click the arrow...etc).

The report will find records #1 & 3, but not #2.

Also, if I would enter "n498" for the parameter, it wouldn't find any of them.

I hope this is making sense...

~bruno71
0
 
LVL 100

Expert Comment

by:mlmcc
ID: 34284074
I'll see what I can do.

I assume there are other values that can occur.

mlmcc
0
 
LVL 100

Accepted Solution

by:
mlmcc earned 500 total points
ID: 34284924
Create this formula
Name - CheckParams
Local StringVar Array strValues;
Local NumberVar paramIndex;
Local NumberVar ValueIndex;
Local BooleanVar boolResult;
boolResult := False;

strValues := Split({Q_26465201.LotNumbers},",");
For ValueIndex := 1 to UBound(strValues) do
   For paramIndex := 1 to UBound({?LotNumber}) do
      If Trim(strValues[ValueIndex]) = Trim({?LotNumber}[paramIndex]) then
         boolResult := True;

boolResult

Use that in your record selection

mlmcc
0
 

Author Comment

by:bruno71
ID: 34285666
Thanks!  I think that worked.  I'll continue to test it.

~bruno71
0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Crystal Reports: 5 Tests for Top Performance It is complete, your masterpiece report.  Not only does it meet your customer’s expectations, it blows them out the water, all they want is beautifully summarised and displayed in a myriad of ways. …
I hate sub reports and always consider them the last resort in any reporting solution.  The negative effect on performance and maintainability is just not worth the easy ride they give the report writer.  Nine times out of ten reporting requirements…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

746 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now