*------------------------------------------------------------------------------ *-- 07/2006 On peut avoir 2 équipes de travail par jour par travailleur. *-- chaque équipe de travail peut elle même avoir 2 types de sursalaire. *-- Ex Equipe IM1 ( infirmière Matin 1 ) peut avoir 7 ho à 100% et 1 Ho à 126% *-- Equipe Fo ( formation ) peut avoir 2 ho à 126% et 2 ho à 100% *-- Un travailleur peut pouvoir réaliser 2 équipes de travail / jour. *-- Le secrétariat social souhaite avoir un fichier où chaque ligne possède *-- le nombre d'ho et un code corrspondant au type de sursalaire. *-- Ex si l'équipe IM1 possède 7ho à 100 % et 1 Ho à 126% le 01/06/2006 *-- 0001234 0000014 20060601 0017 0700 *-- 0001234 0000014 20060601 0017 0100 *-- Code societe Code trav. Date Code sec.social Heures prestées *-- On doit donc filtrer les prestations par jour , type de sursalaire . *-- Comme on peut avoir 4 types de sursalaire différent sur une journée *-- on doit avoir une requête avec 4 clauses UNION. *-- On groupera ensuite sur le type de sursalaire *-- dans une seconde requête comme conseillé sur le NGFr. SELECT E.cnosecretariat , ; E.iid AS 'iemployeid' , ; Horaire.ddate,; PAUSE.iplanpauseid , ; PAUSE.iid,; Horaire.ntypesalaire AS 'sursalaire' ,; Horaire.n100 AS 'totheure'; FROM AMLINE!PAUSE ; INNER JOIN AMLINE!Horaire ON PAUSE.iid = Horaire.cpauseid ; INNER JOIN AMLINE!Employee E ON E.iid = Horaire.iemployeeid; WHERE Horaire.ddate BETW D_debut AND d_fin AND; Horaire.n100 > 0.00 AND Horaire.ntypesalaire > TAUX_NULL; UNION ; SELECT E.cnosecretariat , ; E.iid AS 'iemployeid' , ; Horaire.ddate,; PAUSE.iplanpauseid , ; PAUSE.iid,; Horaire.ntypesursalaire AS 'sursalaire' ,; Horaire.n120 AS 'totheure'; FROM AMLINE!PAUSE ; INNER JOIN AMLINE!Horaire ON PAUSE.iid = Horaire.cpauseid ; INNER JOIN AMLINE!Employee E ON E.iid = Horaire.iemployeeid; WHERE Horaire.ddate BETW D_debut AND d_fin AND; Horaire.n120 > 0.00 AND Horaire.ntypesursalaire > TAUX_NULL; UNION; SELECT E.cnosecretariat , ; E.iid AS 'iemployeid' , ; Horaire.ddate,; PAUSE.iplanpauseid , ; PAUSE.iid,; Horaire.ntypesalaire_2 AS 'sursalaire' ,; Horaire.n100_2 AS 'totheure'; FROM AMLINE!PAUSE ; INNER JOIN AMLINE!Horaire ON PAUSE.iid = Horaire.cpauseid2 ; INNER JOIN AMLINE!Employee E ON E.iid = Horaire.iemployeeid; WHERE Horaire.ddate BETW D_debut AND d_fin AND; Horaire.n100_2 > 0.00 AND Horaire.ntypesalaire_2 > TAUX_NULL; UNION; SELECT E.cnosecretariat , ; E.iid AS 'iemployeid' , ; Horaire.ddate,; PAUSE.iplanpauseid , ; PAUSE.iid,; Horaire.ntypesursalaire_2 AS 'sursalaire',; Horaire.n120_2 AS 'totheure'; FROM AMLINE!PAUSE ; INNER JOIN AMLINE!Horaire ON PAUSE.iid = Horaire.cpauseid2 ; INNER JOIN AMLINE!Employee E ON E.iid = Horaire.iemployeeid; WHERE Horaire.ddate BETW D_debut AND d_fin AND; Horaire.n120_2 > 0.00 AND Horaire.ntypesursalaire_2 > TAUX_NULL; INTO CURSOR temp USE IN 0 Jf SELECT DISTINCT * FROM Jf AS D WHERE ; D.djour BETWEEN D_debut AND d_fin INTO CURSOR DatesFiltred SELECT PADL( ALLTRIM( cnosecretariat) ,7 , "0" ) AS 'cnosecretariat',; iemployeid,; temp.ddate,; iplanpauseid,; SurSalaire,; SUM( totheure ) AS 'TotHo' ,; MAX( Planpause.cnom ) AS 'cnomPlanpause',; SPACE(7) AS cSdCode ,; && on calculera le code nécessaire au secrétariat ensuite. MAX( IIF( ISNULL( D.djour ) , .F. , .T. )) AS 'jfOrWe',; MAX( D.djour ); FROM temp ; INNER JOIN Planpause ON temp.iplanpauseid = Planpause.iid ; LEFT JOIN DatesFiltred D ON D.djour = temp.ddate ; WHERE EMPTY( ALLTRIM(cnosecretariat ) ) =.F.; GROUP BY 1,2,3,4,5 READWRITE INTO CURSOR cursorfinal>The UNION doesn't do SUM. You have to do it yourself on your query result. IN VFP9 you can use result of your query as derived table and sum it
> SELECT u1.iemployeeid , ; > u1.ddate,; > u1.iplanpauseid , ; > SUM( u1.totheure ) AS totheure; > FROM ( <your query here w/o INTO clause > ; > ) u1 ; > GROUP BY 1,2,3 ; > INTO CURSOR temp3 >>You can also try LEFT JOIN
>D_debut = {^2006/06/01} > d_fin = {^2006/06/30} > >SELECT NVL(h1.iemployeeid, h2.iemployeeid) AS iemployeeid, ; > NVL(h1.ddate, ddate) AS ddate,; > PAUSE.iplanpauseid , ; > SUM( NVL(h1.n100 + h1.n120,0) + NVL(h2.n100_2 + h2.n120_2,0)) AS 'totheure'; > FROM AMLINE!PAUSE ; > LEFT JOIN AMLINE!Horaire h1 ; > ON PAUSE.iid = h1.cpauseid ; > AND h1.ddate BETW D_debut AND d_fin ; > LEFT JOIN AMLINE!h2 ; > ON PAUSE.iid = h2.cpauseid2 ; > AND h2.ddate BETW D_debut AND d_fin ; > GROUP BY 1 , 2 , 3 ; > HAVING iemployeeid IS NOT NULL ; > INTO CURSOR temp3 > >>MAybe I missing somethin but I don't se why you need UNION
>> >>I Have Horaire.dbf >>iemployeeid I >>ipauseid I >>ipauseid2 I >>ddate D >>n100 N(8,2) >>n120 n(8,2) >>n100_2 N(8,2) >>n120_2 N(8,2) >> >>I want the sum of n100 + n120 + n100_2 n120_2 per each iemployeeid , ddate , iplanpauseid >> >><PRE> >> >> D_debut = {^2006/06/01} >> d_fin = {^2006/06/30} >> >>SELECT Horaire.iemployeeid , ; >> Horaire.ddate,; >> PAUSE.iplanpauseid , ; >> SUM( Horaire.n100 + Horaire.n120 ) AS 'totheure'; >> FROM AMLINE!PAUSE ; >> INNER JOIN AMLINE!Horaire ON PAUSE.iid = Horaire.cpauseid ; >> WHERE Horaire.ddate BETW D_debut AND d_fin ; >> GROUP BY 1 , 2 , 3 ; >> UNION ; >> SELECT Horaire.iemployeeid , ; >> Horaire.ddate,; >> PAUSE.iplanpauseid , ; >> SUM( Horaire.n100_2 + Horaire.n120_2 ) AS 'totheure'; >> FROM AMLINE!PAUSE ; >> INNER JOIN AMLINE!Horaire ON PAUSE.iid = Horaire.cpauseid2 ; >> WHERE Horaire.ddate BETW D_debut AND d_fin ; >> GROUP BY 1,2,3 ; >> INTO CURSOR temp3 >> >>>>