Page 1 of 1

If..Else if...else

Posted: Mon Oct 03, 2005 9:41 pm
by gateleys
I have 2 stage variables sv1 and sv2, each of which maintain the previous IDs, say empID and storeID, respectively. I need to use a logic such as-

If (sv1=True And sv2=True) then 1 Else If (sv1=True And sv2<> True) then 0 Else 1. The code I used is-

Code: Select all

If (sv1 AND sv2) Then 1 Else If (sv1 AND NOT(sv2)) Then 0 Else 1
Although there are records which satisfy each of the above cases, it always takes the Else path...and give me a 1. Even when I exclude either the first or second clause from the above code, it still gives me the Else condition to return 1. Please tell me where I have gone wrong.

Posted: Mon Oct 03, 2005 9:42 pm
by gateleys
How would you write a routine for the same?

Posted: Mon Oct 03, 2005 9:52 pm
by tcj

Code: Select all

If (Not(IsNull((sv1)) AND Not(IsNull(sv2))) Then 1 Else If (Not(IsNull(sv1)) AND IsNull(sv2)) Then 0 Else 1
I assume that if the previous IDs aren't there then the Stage variable is null.

What is the derivation for the stage variables?

Posted: Mon Oct 03, 2005 10:02 pm
by gateleys
I am using the necessary function(RowProcPreviousCompare) for comparison. My understanding is that the previous value for ID will be there after the first row is processed. Did I miss anything?

Posted: Mon Oct 03, 2005 10:02 pm
by tcj
Yes it will be.

Are you sure that both the records are the same as the previous records at the same time in your data?

Your code should work based on the output of the Rowcompare routine.

Posted: Tue Oct 04, 2005 6:25 am
by kduke
I prefer making each if then a complete statement:

Code: Select all

If (sv1 AND sv2) Then 1 Else "" : (If (sv1 AND NOT(sv2)) Then 0 Else 1)