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!

String field comparison with IF then ELSE statement

Status
Not open for further replies.

psharma1

Programmer
Nov 16, 2009
10
US
I'm using Crystal Report XI to create a simple report with 4 columns using 2 tables and 1 view. The tables are:

Table - District_Master has only 2 fields County_Code & District_Code.

View - VW_V1Master that has the distinct County_Code & District_code selected from another table called V1Master.

Table - DistrictCode_Not_In_V1Master (County_code, District_Code)

I'm using left outer join for joining my District_Master table with the view and the other table.

In the report I've to print:
County_Code, District_Code, In_V1Master(Yes/No), Not_In_V1Master(Yes/No)

For the last 2 columns I wrote 2 different formulas where I'm concatinating the County_code+Dsitrict_Code from the District_Master table and comparing it with the concatenation of County_Code+District_code from the view and the other table and display Yes or No.
The problem is that the IF statement is able to print Yes when the combination exists, but is not able to print No when it does not.

The formula looks like this:

If ({DISTRICT_MASTER.COUNTY_CODE}+{DISTRICT_MASTER.DISTRICT_CODE} in {VW_V1MASTER.COUNTY_CODE}+{VW_V1MASTER.DISTRICT_CODE}) Then
'Yes'
Else 'No'

The 2nd formula is similar to this one but instead of the view I'm using the 2nd table, but there also the Else part to display 'No' is not working.

I've already tried using IIF statement with ISNULL to put a "" for County_Code & District_Code for the view and the other table, in-case the values do not exist, but still the ELSE part is not displaying 'NO'.

Can anyone help to make these formulas work for the Else part.

Thanks in advance!
PS
 
You have to check for null. Null does not automatically convert to a string.

Since you have left-joined, you don't have to concatenate the values to see if they exist. Instead you'll use IsNull() like this:

If IsNull({VW_V1MASTER.COUNTY_CODE}) then 'No' else 'Yes'

-Dell

A computer only does what you actually told it to do - not what you thought you told it to do.
 
Thanks a lot! Yes, you are so right.

Thanks again!
PS
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top