Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Conditional scan, using if
Message
From
17/02/2014 16:30:00
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:
01594522
Views:
51
>Harsh
>
>It's not good to double code because you have to change the second code everytime you change the first..
>
>And as procedures are not allowed in the same method and external ones are complicated,
>I was looking for a way to put all in the same scan, and Rick's solution is best for me.
>
>Thank you and all guys that helped.
>
>Moises

This is better.
if empty(m.variable1)
  lcCond = "field2 = m.variable2"
else
lcCond = "field1 = m.variable1"
endif
scan for &lcCond.
...

The advantages are no duplication in code, single point maintenance, Rushmore will optimize if you have indexes on field1 and field2, the IIF will not fire per row, but once for the entire operation before the scan.

>
>
>>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
>>>
Previous
Reply
Map
View

Click here to load this message in the networking platform