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

IF THEN logic is backwards (Not Working)

Status
Not open for further replies.

markajem

Programmer
Dec 20, 2001
564
US
Okay, so I am a "Deadhead Moment" this Friday afternoon.

Here is what I am attempting to do with an If-Then statement and I can only get it to do either print just itemnumA with the cost or just itemnumB with it's cost.

The results I need are that commoncost always picks up either costA or costB depending on if it is null or not.

[tt]
itemnumA costA itemnumB costB commoncost
83723 1.45 <null> <null> 1.45
73623 2.42 <null> <null> 2.42
<null> <null> 38273 3.25 3.25
63726 1.43 <null> <null> 1.43
<null> <null> 84734 3.45 3.45
<null> <null> 77363 1.24 1.24
66356 2.67 <null> <null> 2.67
[/tt]

Simply put if itemA is not null then print itemnumA's cost. If itemB is not null then print itemnumB's cost. ItemnumA or itemnumB will never be null for the same line; it will only be one or the other.

Thanks so much.

Mark
 
Try:

if isnull({table.itemnumA}) then {table.costB} else
{table.costA}

-LB
 
Nope; didn't work. Only brings up itemnumB's cost, not one or the other.

Thanks
 
I would change it a bit since you are not testing CostB for null

WhilePrintingRecords;

numberVar Commoncost;

if not isnull({table.itemnumA}) then
Commoncost := {table.costA}
else if not isnull({table.itemnumB}) then
Commoncost := {table.costB}
else
Commoncost := 0;

The latter will handle a data problem if both were null. (not supposed to happen....but...



Jim Broadbent

The quality of the answer is directly proportional to the quality of the problem statement!
 
I was assuming that {table.ItemNumA} and {table.ItemNumB} are different fields. Is this true? Also, can you verify that if you lay out the fields as you have shown above in the detail section, that the data appears as you have shown for the item and cost fields? If so, my formula should have worked--unless you actually have blanks, not nulls, in which case you could try:

if isnull({table.itemnumA}) or
trim({table.itemnumA}) = "" then
{table.costB} else
{table.costA}

-LB

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top