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 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190
| CREATE DATABASE '..\Data\Base.fdb' page_size 4096 DEFAULT CHARACTER SET ISO8859_1;
-- ===============================
-- Création de la table 'horaires'
-- ===============================
CREATE TABLE HORAIRES (
CODE_H VARCHAR(40) NOT NULL collate fr_fr,
NO_PER SMALLINT,
NO_PROJ SMALLINT,
SOUS_PROJ SMALLINT,
STARTTIME TIMESTAMP,
ENDTIME TIMESTAMP,
SUJET VARCHAR(40) NOT NULL collate fr_fr,
NOTES VARCHAR(255) NOT NULL collate fr_fr,
COULEUR INTEGER,
IMAGE SMALLINT
);
-- =========================
-- Insertion dans 'horaires'
-- =========================
insert into horaires (code_h,no_per,no_proj,sous_proj,starttime,endtime,sujet,notes,couleur,image) values ('c1', 59, 22, 1, '2016/02/09 09:00:00', '2016/02/09 18:00:00', 'bla bla', 'rien', 5, 2);
insert into horaires (code_h,no_per,no_proj,sous_proj,starttime,endtime,sujet,notes,couleur,image) values ('c1', 59, 22, 2, '2016/02/29 15:00:00', '2016/02/29 19:00:00', 'bla bla', 'rien', 5, 2);
insert into horaires (code_h,no_per,no_proj,sous_proj,starttime,endtime,sujet,notes,couleur,image) values ('c1', 59, 22, 3, '2016/03/05 07:00:00', '2016/03/05 14:00:00', 'bla bla', 'rien', 5, 2);
-- ====================
-- Vidage de 'horaires'
-- ====================
select * from horaires;
CODE_H NO_PER NO_PROJ SOUS_PROJ STARTTIME ENDTIME SUJET NOTES COULEUR IMAGE
======================================== ======= ======= ========= ========================= ========================= ======================================== =============================================================================== ============ =======
c1 59 22 1 2016-02-09 09:00:00.0000 2016-02-09 18:00:00.0000 bla bla rien 5 2
c1 59 22 2 2016-02-29 15:00:00.0000 2016-02-29 19:00:00.0000 bla bla rien 5 2
c1 59 22 3 2016-03-05 07:00:00.0000 2016-03-05 14:00:00.0000 bla bla rien 5 2
-- ============
-- Requête N°01
-- ============
select STARTTIME, ENDTIME
from HORAIRES
where NO_PER = 59
and NO_PROJ = 22
and STARTTIME BETWEEN '2016-02-01' AND '2016-03-31';
STARTTIME ENDTIME
========================= =========================
2016-02-09 09:00:00.0000 2016-02-09 18:00:00.0000
2016-02-29 15:00:00.0000 2016-02-29 19:00:00.0000
2016-03-05 07:00:00.0000 2016-03-05 14:00:00.0000
-- ============
-- Requête N°02
-- ============
select STARTTIME, ENDTIME
from HORAIRES
where NO_PER = 59
and NO_PROJ = 22
and STARTTIME BETWEEN '2016-02-01' AND '2016-02-29';
STARTTIME ENDTIME
========================= =========================
2016-02-09 09:00:00.0000 2016-02-09 18:00:00.0000
-- ============
-- Requête N°03
-- ============
select STARTTIME, ENDTIME
from HORAIRES
where NO_PER = 59
and NO_PROJ = 22
and STARTTIME BETWEEN '2016-02-01 00:00:00.0000' AND '2016-02-29 23:59:59.9999';
STARTTIME ENDTIME
========================= =========================
2016-02-09 09:00:00.0000 2016-02-09 18:00:00.0000
2016-02-29 15:00:00.0000 2016-02-29 19:00:00.0000
-- ============
-- Requête N°04
-- ============
select STARTTIME, ENDTIME
from HORAIRES
where NO_PER = 59
and NO_PROJ = 22
and cast(STARTTIME as date) BETWEEN '2016-02-01' AND '2016-02-29';
STARTTIME ENDTIME
========================= =========================
2016-02-09 09:00:00.0000 2016-02-09 18:00:00.0000
2016-02-29 15:00:00.0000 2016-02-29 19:00:00.0000
-- ======================
-- Create procedure N° 01
-- ======================
SET TERM $;
CREATE PROCEDURE proc1 (Code_PRO SMALLINT,
Code_PER SMALLINT,
date_deb date,
date_fin date)
returns (total_hor integer) /* Récupération des lignes */
AS
DECLARE h_debut timestamp;
DECLARE h_fin timestamp;
DECLARE prov_hd integer;
DECLARE prov_md integer;
DECLARE prov_hf integer;
DECLARE prov_mf integer;
BEGIN
total_hor = 0;
for select STARTTIME, ENDTIME
from horaires
where NO_PROJ =:Code_PRO /* Code projet */
and NO_PER =:Code_PER /* Code personnel */
and STARTTIME >= :date_deb
and ENDTIME <= :date_fin
into :h_debut,
:h_fin
do begin
PROV_HD = extract(hour from h_debut);
PROV_MD = extract(minute from h_debut);
PROV_HF = extract(hour from h_fin);
PROV_MF = extract(minute from h_fin);
if (PROV_HF = 0) then PROV_HF = 24;
total_hor = total_hor + ((PROV_HF-PROV_HD)*60) + (PROV_MF-PROV_MD);
end
suspend;
END$
SET TERM ;$
select total_hor from proc1(22, 59, '2016-02-01', '2016-03-31');
TOTAL_HOR
============
1200
-- ======================
-- Create procedure N° 02
-- ======================
SET TERM $;
CREATE PROCEDURE proc2 (Code_PRO SMALLINT,
Code_PER SMALLINT,
date_deb date,
date_fin date)
returns (total_hor integer) /* Récupération des lignes */
AS
BEGIN
total_hor = 0;
select sum(datediff(minute from starttime to endtime))
from horaires
where NO_PROJ =:Code_PRO /* Code projet */
and NO_PER =:Code_PER /* Code personnel */
and STARTTIME >= :date_deb
and ENDTIME <= :date_fin
into :total_hor;
suspend;
END$
SET TERM ;$
commit;
select total_hor from proc2(22, 59, '2016-02-01', '2016-03-31');
TOTAL_HOR
============
1200
exit;
Appuyez sur une touche pour continuer... |
Partager