1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114
| CREATE PROCEDURE RecupDonnees(FINREQ VARCHAR(200), DATED DATE, DATEF DATE)
RETURNS(CAG,MARGENG,PDSG,NBFACG,MOYARTG,NBCLIG,
CAF1,CAF2,CAF3,CAF5,CAF6,CAF8,CAF9,
MARGEF1,MARGEF2,MARGEF3,MARGEF5,MARGEF6,MARGEF8,MARGEF9,
NBCLILCR,CALCR,CATELEVT,CANOUV,PDSNOUV,NBCLINOUV,
CAMAIL,PDSMAIL,NBCLIMAIL,CAPS,PDSPS,NBCLIPS)
AS
DECLARE VARIABLE CAF NUMERIC(15,4);
DECLARE VARIABLE MARGEF NUMERIC(15,4);
DECLARE VARIABLE FAM INTEGER;
BEGIN
FOR
SELECT FAMILLE,Sum(CA),Sum(MARGE_N)
FROM CONDENS_LIGNES
WHERE DATELIV BETWEEN :DATED AND :DATEF
AND STAT_LI=1 AND STAT_CO=1
AND :FINREQ
GROUP BY FAMILLE
INTO :FAM, :CAF, :MARGEF
DO
BEGIN
IF(:FAM=1)
THEN
BEGIN
CAF1=:CAF;
MARGEF1=:MARGEF;
END
IF(:FAM=2)
THEN
BEGIN
CAF2=:CAF;
MARGEF2=:MARGEF;
END
IF(:FAM=3)
THEN
BEGIN
CAF3=:CAF;
MARGEF3=:MARGEF;
END
IF(:FAM=5)
THEN
BEGIN
CAF5=:CAF;
MARGEF5=:MARGEF;
END
IF(:FAM=6)
THEN
BEGIN
CAF6=:CAF;
MARGEF6=:MARGEF;
END
IF(:FAM=8)
THEN
BEGIN
CAF8=:CAF;
MARGEF8=:MARGEF;
END
IF(:FAM=9)
THEN
BEGIN
CAF9=:CAF;
MARGEF9=:MARGEF;
END
END
SELECT Sum(CA),Sum(MARGE_N),Sum(PDS),Count(DISTINCT NOFAC)
FROM CONDENS_COM
WHERE DATELIV BETWEEN :DATED AND :DATEF
AND STAT=1
AND :FINREQ
INTO :CAG,:MARGENG,:PDSG,:NBFACG;
SELECT Count(DISTINCT NOCLI)
FROM CONDENS_COM
WHERE DATELIV BETWEEN :DATED AND :DATEF
AND STAT=1
AND NOCLI NOT BETWEEN 300000 AND 399999
AND :FINREQ
INTO NBCLIG;
CREATE VIEW ART (NBART,NOCLI)
AS
SELECT Count(DISTINCT NOARTI),NOCLI
FROM CONDENS_LIGNES
WHERE DATELIV BETWEEN :DATED AND :DATEF
AND STAT_LI=1 AND STAT_CO=1
AND :FINREQ
GROUP BY NOCLI;
SELECT AVG(NBART)
FROM ART
INTO :MOYARTG;
DROP VIEW ART;
SELECT SUM(CA),COUNT(DISTINCT NOCLI)
FROM CONDENS_COM
WHERE DATELIV BETWEEN :DATED AND :DATEF
AND STAT=1
AND TYPE_PAIEMENT LIKE 'TD%'
AND :FINREQ
INTO :CALCR, :NBCLILCR;
SELECT SUM(CA)
FROM CONDENS_COM
WHERE DATELIV BETWEEN :DATED AND :DATEF
AND STAT=1
AND (NOOPE IN (10,11,14,32,29,50,62,63,64,90,91,92)
AND :FINREQ
INTO :CATELEVT;
END |
Partager