Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Formula Field with Multiple Cases

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
I'm trying to develop a formula field with user defined conditions, ie... if {table.field} = <value> then &quot;symbol&quot;. the problem I'm having is that I need the formula to look through a list of values, and print each symbol for each associated value. I've tried using If/Then statements, but that only checks one case and exits.. Any ideas?
 
You have options.

I infer parameters from &quot;User Defined Conditions&quot;.

Anyway, not fully understanding the request:

You can use if then ELSE.
// Example using a IN to allow for multiple values
// searched with a single return
if {MyField} IN [&quot;Hello&quot;, &quot;Goodbye&quot;,...] then
&quot;Hi-Bye&quot;
Else
...

Or you can use a Select Case, depending upon your version of Crystal.

select {MyTable.MyField}
case &quot;Some value&quot; : 'Hi'
case &quot;Another value&quot; : 'Bye'
...
default : 'Dunno'

-k kai@informeddatadecisions.com
 
You can nest if-then statements:

if <condition is true> then <result> else
If <condition2 is true> then <result2> else......


Software Support for Macola, Crystal Reports and Goldmine
dgilsdorf@mchsi.com
 
thanks k, i see what your saying, but I still can't get multiple cases to work. Let me give a better description I'm pulling data from two tables:
Record Table Record_Detail Table
record_id record_id
date_start record_accsy_id
date_end
In this case, I have record_id 999 which has multiple entries in the record_detail table, ie:
Record_id Record_accsy_id
999 01
999 02
999 03
999 04
I already have a select filter that only pulls certain record_accsy_id's, {record_detail.record_accsy_id} in (01, 02, 03). Now I have an additional column in my report that needs to tag a specific abbreviation to each record_accsy_id. (01 = &quot;AA&quot;, 02 = &quot;BB&quot;, 03 = &quot;CC&quot;). The ending report looking something like

Record Accessory
999 AA BB CC

Maybe this provides a clearer explaination of what i'm attempting to do. Thanks for your responses!
 
Based on your example, Book, you should be able to use any one of the explanations offered to you by SV or Dgillz.

For instance, something like...:

if record_accsy_id = 01 then 'AA'
else
if record_accsy_id = 02 then 'BB'
else
//etc etc etc for as many conditions as you like.

...should suit your purposes down to the ground.

If you wanted to return one value for a group of conditions, then you'd use 'in' as described before.

Naith
 
to get this kind of a look:

Record Accessory
999 AA BB CC

from your data have it printed in the group footer for Record_ID

create 3 formulas

******************************************************

@Initialization (suppressed in the Record_ID Group header)

WhilePrintingRecords;
StringVar result := &quot;&quot;;

******************************************************

@assembleSymbols (suppressed in the details section)

WhilePrintingRecords;
StringVar result ;

If {{Record_Detail.Record_accsy_id}) = &quot;01&quot; then
result := result + &quot;AA&quot; + &quot; &quot;
else If {{Record_Detail.Record_accsy_id}) = &quot;02&quot; then
result := result + &quot;BB&quot; + &quot; &quot;
else If {{Record_Detail.Record_accsy_id}) = &quot;03&quot; then
result := result + &quot;CC&quot; + &quot; &quot;;

******************************************************

@displayResult (Placed in Report_ID Group footer)

WhilePrintingRecords;
StringVar result ;

result ;

******************************************************

now when you place these fields in the footer you will get the desired result

{record.record_ID} {@displayResult}


Jim Broadbent
 
Thanks for the help. The formulas worked perfectly...... Outstanding!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top