>>And here's another thought..., Depending on
when macro expansion takes place, a macro may or may not give better performance. If the macro expansion takes place when the SCAN statement is initially encountered, then we might see an improvement in speed. If the macro expansion takes place at every loop iteration then you'll see a significant degradation in speed.
>>
>>
select mytable
>>cCond = "iif(empty(variable1), field2 = variable2, field1 = variable1)"
>>scan for &cCond.
>> * Code here
>>endscan
.
>
>Macro expansion occurs only at beginning of scan. The IIF inside the condition would still be executing per row. The following moves the IIF out of the scan.
>
>if empty(variable1)
> lccond = "field2 = variable2"
>else
> lccond = "field1 = variable1"
>endif
>scan for &lccond.
>...
>
>or
>lcNum=iif(empty(variable1),"2","1")
>lcCond = "field" + m.lcNum + " = variable" + m.lcNum
>scan for &lcCond
fully correct on preferring macro expansion to iif() if encountered in SQL or xBase-table-scope identifier "FOR".
Your solution has the added benefit of being Rushmore optimized if indices exist on field1 or field2.