Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Update Sql Command
Message
Information générale
Forum:
Visual FoxPro
Catégorie:
Base de données, Tables, Vues, Index et syntaxe SQL
Divers
Thread ID:
01202518
Message ID:
01203684
Vues:
27
Try something like
  CREATE CURSOR Agenda ( iid I , ddate D(8) , itraiterId I , nstock N(8,2) )

  INSERT INTO Traiter ( iid , nstock ) VALUES ( 1 , 14.25 )
  INSERT INTO Traiter ( iid , nstock ) VALUES ( 2 , 4.25 )
  INSERT INTO Traiter ( iid , nstock ) VALUES ( 3 , 0 )


  INSERT INTO Agenda ( iid , ddate, itraiterId ) VALUES ( 1 , DATE() , 2)
  INSERT INTO Agenda (iid , ddate, itraiterId ) VALUES ( 2 , DATE() , 3 )
  INSERT INTO Agenda (iid , ddate, itraiterId ) VALUES ( 3 , DATE() , 1 )
  INSERT INTO Agenda ( iid , ddate, itraiterId ) VALUES (4 , DATE() , 2) 
  INSERT INTO Agenda ( iid , ddate, itraiterId ) VALUES (5 , DATE()-1 , 2) 



  vp_date = DATE()

* Step 1. Get Stock for the latest previous date
SELECT Ag.iID, Ag.iTraiterID, Prev.nStock FROM Agenda ag ;
inner join (select iTraiterID, max(dDate) as PrevDate ;
from Agenda where dDate < vp_Date group by 1) Prev ;
on Ag.iTraiterID = Prev.iTraiterID ;
and Ag.dDate = vp_Date INTO CURSOR SqlOut

* Create records to update
SELECT T.iId, NVL(SqlOut.nStock,T.nStock) as nStock ;
FROM Traiter t LEFT JOIN SqlOut ON T.iId = SqlOut.iTraiterID ;
INTO CURSOR curUpdate 

** Update records
update agenda set nStock = curUpdate.nStock ;
from Agenda inner join curUpdate on Agenda.iTraiterID = curUpdate.iID where Agenda.dDate = vp_Date
I did it in multiple steps for clarity and I could not really test it without VFP9.

In VFP9 you can combine all of these into one statement, but I would not try to do it.


>Yes
>
>
>
>>Only records with apd.ddate = vp_date should be updated, right?
>>
>>>Just !
>>>VP_date - 1
>>>
>>>
>>>>>I want for each day put the stock of medicament.
>>>>>
>>>>>
>>>>
>
>>>>>AGENDA.DBF
>>>>>*--- NAME             MEDICAMENT     DATE          CONSOMMATION      STOCK
>>>>>Ex : MILCENT bernhart TEMESTA 2.5    14/03/2007    1                   50 ( Before )
>>>>>MILCENT bernhart TEMESTA 2.5    15/03/2007    1                   49 ( Before )
>>>>>
>>>>>TRAITER.DBF       STOCK ( BEGINNING )
>>>>>IRESIDENTID           50
>>>>
>>>>>
>>>>>FOR 14/03/2007 IF NO MEDICAMENT for 13/03/2007 Take stock Of traiter.dbf ...( 50 ).
>>>>
>>>>Than condition apd.ddate < vp_date is incorrect because it'll pick up all previous record but you want only the latest one before current, right?
If it's not broken, fix it until it is.


My Blog
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform