Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Update one table based on another table
Message
De
30/03/2005 16:02:57
 
 
Information générale
Forum:
Visual FoxPro
Catégorie:
Base de données, Tables, Vues, Index et syntaxe SQL
Versions des environnements
Visual FoxPro:
VFP 8 SP1
OS:
Windows XP SP2
Divers
Thread ID:
00999981
Message ID:
01000096
Vues:
17
>>>Hi everybody,
>>>
>>>Is it possible to update one table based on another?
>>>
>>>Here is my attempt:
>>>
>>>UPDATE trans SET cCommissioned_Owner = curt.cOwner WHERE trans.ctrans_pk = Curt.ctrans_pk
>>>
>>>In curt I put two records, but only one record was updated in Trans. Is it possible to do or it would be better to scan curt and update one record in a time (or use replace command - which is better?)
>>>
>>>Thanks a lot in advance.
>>
>>If some conditions are valid:
>>
>>UPDATE TRANS SET cCommissioned_Owner = LOOKUP(Curt.cOwner,ctrans_pk,Curt.ctrans_pk)
>>* or + restricted
>>REPLACE IN TRANS ALL FOR ctrans_pk=LOOKUP(Curt.ctrans_pk,ctrans_pk,Curt.ctrans_pk) ;
>>cCommissioned_Owner WITH Curt.cOwner
>>
>
>Thanks. I have one more condition. In curT I want to only use records with iAssigned = 1. So, here is how I coded it (testing now):
>
>** Now let's update Trans, Trans_Employee_Queues and Employee_Queue_Schedules tables
>BEGIN TRANSACTION
>  SELECT(m.tcAlias)
>  SCAN FOR iAssigned = 1
>
>      lcTrans_pk = cTrans_pk
>
>      lcTrans_Employee_Queues_pk = cTrans_Employee_Queues_pk
>
>      lcCommission_Owner_UsgrLink_fk = cCommission_Owner_UsgrLink_fk
>
> 	  lcQueue_Names_fk = cQueue_Names_fk
> 	
> 	  IF SEEK(m.lcTrans_pk,"UpdTrans")
>	      replace cCommissioned_Owner with m.tcUserID IN UpdTrans
>	  ENDIF
>	
>	  IF SEEK(m.lcTrans_Employee_Queues_pk,"UpdEmp_Queues")
>	      replace cCommission_Owner_UsGrLink_fk ;
>	      with m.lcCommission_Owner_UsgrLink_fk, ;
>	      cQueue_Names_fk WITH m.lcQueue_Names_fk ;
>	      IN UpdEmpQueues
>	  ENDIF
>	
>      INSERT INTO UpdSchedules (cTrans_Employee_Queues_fk, tScheduled_Time, iActive_At_Day_Start_Flag) ;
>      VALUES ;
>          (m.lcTrans_Employee_Queues_pk, m.ttTime, 1)
>  ENDSCAN
>END TRANSACTION
>
If you want, simplified a bit
BEGIN TRANSACTION 
  SELECT(m.tcAlias)
  SCAN FOR iAssigned = 1

     IF SEEK(cTrans_pk,"UpdTrans")
	replace UpdTrans.cCommissioned_Owner with m.tcUserID
     ENDIF

     IF SEEK(cTrans_Employee_Queues_pk,"UpdEmpQueues")
	replace UpdEmpQueues.cCommission_Owner_UsGrLink_fk ;
                    WITH cCommission_Owner_UsgrLink_fk ;
	       , UpdEmpQueues.cQueue_Names_fk;
                    WITH cQueue_Names_fk    
     ENDIF

     lcTrans_Employee_Queues_pk = cTrans_Employee_Queues_pk

     INSERT INTO UpdSchedules ;
        ( cTrans_Employee_Queues_fk;
        , tScheduled_Time;
        , iActive_At_Day_Start_Flag) ;
      VALUES ;
        (m.lcTrans_Employee_Queues_pk;
        , m.ttTime;
        , 1)

  ENDSCAN
END TRANSACTION 
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform