Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
How to do this with sql
Message
From
25/06/2011 10:02:58
 
 
To
25/06/2011 09:24:54
Hilmar Zonneveld
Independent Consultant
Cochabamba, Bolivia
General information
Forum:
Visual FoxPro
Category:
Databases,Tables, Views, Indexing and SQL syntax
Environment versions
Visual FoxPro:
VFP 9 SP2
OS:
Windows XP SP2
Network:
Windows XP
Database:
Visual FoxPro
Application:
Desktop
Miscellaneous
Thread ID:
01515989
Message ID:
01516021
Views:
73
Agree with your ideas, would add:

instead of append blank / gather use
insert into newcustomer from name oScat
as the other code is aleady aliased, the to selects inside the loop can be left out as well.
scan
     scatter name oScat
     if  not seek(m.oScat.accode,'newcustomer','accode')
       insert into newcustomer from name oScat
    else
       && see below
    endif
endscan
depending on the kind of disc you can think of rewriting the else part as
replace in newcustomer ;
   address1 with evl(newcustomer.address1, m.oScat.address1);
   address2 with evl(newcustomer.address2, m.oScat.address2)
or for SSD
if empt(newcustomer.address1+newcustomer.address2) && betting on compatible type, else use empty() and empty()
   replace in newcustomer ;
      address1 with evl(newcustomer.address1, m.oScat.address1);
      address2 with evl(newcustomer.address2, m.oScat.address2)
endif
regards

thomas

>I believe that is a bit too complicated to do with SQL. However, I have the following suggestions for improving your code:
>
>1) Don't abbreviate commands. It makes code more difficult to read.
>
>2) Instead of SCATTER MEMVAR, it is probably better to use SCATTER NAME ... This will generate a single variable, similar to an object, and you can then access its properties by name.
>
>3) To loop through all the records of a table, use SCAN ... ENDSCAN. This way, you don't need (a) the GO TOP, (b) the condition (WHILE NOT EOF(...)), and (c) the SKIP at the end of the loop.
>
>>
>>use 1001\customer again in 0 alias oldcustomer shared 
>>use 1002\customer again in 0 alias newcustomer shared
>>sele newcustomer
>>set order to accode
>>sele oldcustomer
>>set order to accode
>>go top
>>do while not eof('oldcustomer')
>>     scatter memvar
>>     sele newcustomer
>>     if  not seek(m.accode,'newcustomer','accode')
>>         appe blank in newcustomer
>>         gather memvar
>>    else
>>          if empt(newcustomer.address1)
>>             repl newcustomer.address1 with m.address1 in newcustomer
>>         endif
>>          if empt(newcustomer.address2)
>>             repl newcustomer.address2 with m.address2 in newcustomer
>>         endif
>>    endif
>>    sele oldcustomer
>>    skip
>>enddo
>>
>>
>>
>>how to do this with sql.
>>
>>Warm regards,
>>mk.
Previous
Reply
Map
View

Click here to load this message in the networking platform