Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Conditional scan, using if
Message
From
17/02/2014 14:16:25
 
 
To
17/02/2014 12:54:54
Mike Yearwood
Toronto, Ontario, Canada
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Environment versions
Visual FoxPro:
VFP 9 SP2
OS:
Windows Server 2012
Network:
Windows 2008 Server
Database:
MS SQL Server
Application:
Web
Miscellaneous
Thread ID:
01594372
Message ID:
01594512
Views:
44
>>>Sir, Scanning like the code you have suggested and the code I gave below makes the difference in Speed or performance.
>>>
>>>
>>>Select mytable
>>>if empty (variable1)
>>>scan for field2 = variable2
>>>Endscan
>>>Else
>>>scan for field1 = variable1
>>>Endscan
>>>Endif
>>>
>>>
>>>I am asking this just for my knowledge, if yes I will also make changes in my all of codes accordingly.
>>>Regards
>>>
>>>
>>>
>>>
>>>>
select mytable
>>>>
>>>>scan for iif(empty(variable1), field2 = variable2, field1 = variable1)
>>>>    * Code here
>>>>endscan
>>>>
>>
>>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

Thanks for catching the stupid mistake I'd made -- I was meaning to change the assignment statement (so that the IIF wasn't part of the string), but got interrupted in mid-post and lost train of thought before I'd clicked on the Send button...
Previous
Reply
Map
View

Click here to load this message in the networking platform