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

Assign value in left outer join when right table value does not exist 1

Status
Not open for further replies.

cathyg18

MIS
Mar 12, 2001
54
US
I have a query with a left outer join, and a formula that calculates based on comparing one field in each table. I am having difficulty in making the value 0 when the field does not exist in the right table.

This is the formula I'm using right now.

IF {LEFTTABLE.VALUE} <> {RIGHTTABLE.VALUE}
and {LEFTTABLE.VALUE} <> 0
THEN {ANOTHERTABLE.VALUE} ELSE
if not isnull ({LEFTTABLE.VALUE}) then {LEFTTABLE.VALUE}
else
0

It works fine for everything except when there is no matching record in RIGHTTABLE. Instead of putting a 0 in the calculated field, it puts nothing, which then screws up other calculations that are based on this one.

Is there hope?

Thanks,
Cathy
 
hi
what the value of
{ANOTHERTABLE.VALUE}
since its returning that value

cheers

pgtek
 
I'm not sure I quite understand what you are asking me here. Could you expand a bit?
 
If no value exists for the right table, then that field will be null. You need to check if that field is null before you compare it to the left table/field because Crystal doesn't compare nulls with a known value predictably. Therefore



if not isNull({RIGHTTABLE.VALUE}) and
{LEFTTABLE.VALUE} <> RIGHTTABLE.VALUE} and
{LEFTTABLE.VALUE} <> 0 then
{ANOTHERTABLE.VALUE}
else if not isnull ({LEFTTABLE.VALUE}) then
{LEFTTABLE.VALUE}
else 0;
 
Ok
you say if not isNull({RIGHTTABLE.VALUE}) and
{LEFTTABLE.VALUE} <> RIGHTTABLE.VALUE} and
{LEFTTABLE.VALUE} <> 0 then
{ANOTHERTABLE.VALUE} (what do you want this fied to return a blank, a zero or a 1???????????????)
 
Works like a charm!!!

Thank you so much. I have been beating my head against this wall for several days now.

Cathy
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top