Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Calculating times
Message
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Divers
Thread ID:
00697029
Message ID:
00698284
Vues:
14
>Thanks Mark,
>Yes that is it ,
>only ihave written the samples eg "Start 1 ...." randomly must be logical strings so
>
>if the strings was like under how could be the SQL syntax calculating the times between these times ?
>
>05/09/2002 14:53 PM Start 1 M2A|M4D|M6A|M8A|M0A
>05/09/2002 14:54 PM Start 1 M2A|M4D|M6A|M8A|M0A|M1A|M3D|M5A|M7A|M9A
>05/09/2002 14:58 PM Start 1 M2D|M3D|M5A|M7A|M9A

here goes. I created a table named TEST with fields named LOGDATE [DateTime] and CSTRING [C100]. The CSTRING field contains the M#A|M#D strings.
lcGroupBy = [MachineName, LogDate]
lnI = 0
lcSQL = []

FOR lnI = 0 TO 9
   IF NOT EMPTY(lcSQL)
      lcSQL = lcSQL + [ UNION ]
   ENDIF
   lcSQL = lcSQL ;
        + [SELECT 'M] + TRANSFORM(lnI) + [' MachineName, MIN(LogDate) LogDate, .T. RunStart ] ;
        + [FROM Test WHERE CString LIKE '%M] + TRANSFORM(lnI) + [A%'] ;
        + [GROUP BY ] + lcGroupBy
ENDFOR
lcSQL = lcSQL + [ ORDER BY MachineName INTO CURSOR crsMachineStarts]
&lcSQL

lcSQL = []
FOR lnI = 0 TO 9
   IF NOT EMPTY(lcSQL)
      lcSQL = lcSQL + [ UNION ]
   ENDIF
   lcSQL = lcSQL ;
        + [SELECT 'M] + TRANSFORM(lnI) + [' MachineName, MAX(LogDate) LogDate, .F. RunStart ] ;
        + [FROM Test WHERE CString LIKE '%M] + TRANSFORM(lnI) + [D%'] ;
        + [GROUP BY ] + lcGroupBy
ENDFOR
lcSQL = lcSQL + [ ORDER BY MachineName INTO CURSOR crsMachineEnds]
&lcSQL

SELECT crsMachineStarts.* FROM crsMachineStarts ;
UNION ALL SELECT crsMachineEnds.*  FROM crsMachineEnds ;
ORDER BY 1, 2 INTO CURSOR crsMachineRuns

CREATE CURSOR crsRunTimes (MachineName C(2), nRunTime I)

SELECT crsMachineRuns
SCAN
   IF NOT RunStart
      LOOP
   ENDIF
   lcMachine = crsMachineRuns.MachineName
   ldStart = crsMachineRuns.LogDate
   DO WHILE crsMachineRuns.MachineName = lcMachine AND crsMachineRuns.RunStart
      SKIP IN crsMachineRuns
   ENDDO
   IF MachineName = lcMachine AND NOT RunStart
      INSERT INTO crsRunTimes VALUES (lcMachine, crsMachineRuns.LogDate - ldStart)
   ELSE
      SKIP -1 IN crsMachineRuns
   ENDIF
ENDSCAN
Mark McCasland
Midlothian, TX USA
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform