Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
How to join tables with a condition if field is empty
Message
 
 
À
22/06/2009 23:12:27
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Divers
Thread ID:
01407723
Message ID:
01407756
Vues:
34
>I have this query
>
>


>SELECT userID, swipedate, MIN(SwipeTime) AS Time2 ;
> FROM temp WHERE VAL(swipetime) BETWEEN 1200 AND 1300 AND eventid='OUT' ;
> GROUP BY userID, swipedate ;
> INTO CURSOR c_LunchOut
>
>


>
>There may be cases when an employee time-outs early, say 11:30.. leaving empty records on this query since I put the between 1200 and 1300 condition.. so I put another query on my form..
>
>


>SELECT userID, swipedate, MAX(SwipeTime) AS Time2 ;
> FROM temp WHERE eventid='OUT' AND VAL(swipetime) < 1200;
> GROUP BY userID, swipedate ;
> INTO CURSOR c_AMUndertime
>


>
>I'd like to join these two tables with a condition that if TIME2 on c_LunchOut is empty, the record on c_AMUndertime will be used or saved in that table..
>
>How should I do this?
>
>Pls help. TIA.

Evelyn,


I believe in your case you're looking for the UNION clause, e.g.
 SELECT userID, swipedate, MIN(SwipeTime) AS Time2 ;
	FROM temp WHERE VAL(swipetime) BETWEEN 1200 AND 1300 AND eventid='OUT' ; 
	GROUP BY userID, swipedate ;
   UNION ;
  SELECT userID, swipedate, MAX(SwipeTime) AS Time2 ;
	FROM temp WHERE eventid='OUT' AND VAL(swipetime) < 1200;
	GROUP BY userID, swipedate ;
       into cursor cAllPeopleWithLunchesAndWithout
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