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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Is there a quicker way?? 2

Status
Not open for further replies.

jcl5

IS-IT--Management
Dec 6, 2002
89
GB
Hi

Using Crystal 10 and Oracle 8i

I need to create a formula that translates a code into text and am currently doing this with a simple if, then, else statement. It is fairly long and tedious and was wondering if there is a better way of doing it.

When using a different report writer some years ago there was a function called Case that worked like an if, then, else. e.g.

CASE(ATTENDANCE.NOATT_COD,'CHEQUE','CHEQUES','INVOIC','INVOICE_REQUEST',
'PDCARD','CARD_PAYMENT','PDWEB','WEB_PAYMENT','TXCHQ','TRANSFER','OTHER')

The case statement in Crystal doesn't seem to do the same and I'm not a programmer/developer so appears quite complicated to me.

Is there a similar function in Crystal?

Many thanks

jcl5
 
I can't see the end of your statement to know what the then part is, but you could use:

select {table.amt}
case 1,2 : "First Two"
case 3 to 5 : "Next Three"
default : "Other"

It looks like you might be using a parameter to select different fields. Then it might look like the following where {?parm} is a string parameter with options Amount, Name, Date:

select {?parm}
case "Amount" : totext({table.amt},2)
case "Name" : {table.name}
case "Date" : totext({table.date},"MM/dd/yy")
default : ""

Note that like an if/then, the case results must be of the same datatype. As far as I know, there is no real advantage to the case statement over an if/then.

-LB
 
The Case statement used by your other report writer worked like an IIF in Crystal (and most languages), which can be difficult to maintain because of readability, I'd go with a CASE structure similar to LB's suggestion (a bit tidier) or use a conventional IF (most are familiar with this).

CASE structure:

SELECT (ATTENDANCE.NOATT_COD}
case "CHEQUE": "CHEQUES"
case "INVOIC" : "INVOICE_REQUEST"
case "PDCARD" : "CARD_PAYMENT"
case "PDWEB" : "WEB_PAYMENT"
case "TXCHQ" : "TRANSFER"
default : "OTHER"

IF structure:

If (ATTENDANCE.NOATT_COD}= "CHEQUE" then
"CHEQUES"
else
If (ATTENDANCE.NOATT_COD}= "INVOIC" then
"INVOICE_REQUEST"
else
If (ATTENDANCE.NOATT_COD}= "PDCARD" then
"CARD_PAYMENT"
else
If (ATTENDANCE.NOATT_COD}= "PDWEB" then
"WEB_PAYMENT"
else
If (ATTENDANCE.NOATT_COD}= "TXCHQ" then
"TRANSFER"
else
"OTHER"

Best would be to add a reference/lookup table with a (ATTENDANCE.NOATT_COD} and a description to the database and just join them via the (ATTENDANCE.NOATT_COD} field

-k
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top