6 SET QUOTED_IDENTIFIER
OFF
9 ALTER PROCEDURE [dbo
].
[auf_p_etat_resultats_p4_ex_precedent_2011
]
13 @retraitement
varchar(3)
17 -- 2-GRI : groupé par implantation
18 -- 3-GRB : groupé par bureau
20 -- 5-XXX : implantation XXX
21 -- @retraitement: Oui/Non
25 DECLARE @lib_periode
varchar(100)
26 DECLARE @categorie
varchar(1)
27 DECLARE @publication
varchar(3)
31 --- extraire la catégorie de 'état
33 SELECT @categorie
= LEFT(ltrim(@code
),1)
35 IF ( @exercice
= 0 ) BEGIN
36 -- pour permettre aux états sur IWR de récuperer l'éxercice et la période courants
37 SELECT @publication
= 'oui'
44 WHERE code_etat
= 'ICG'
47 SELECT @publication
= 'non'
49 SELECT @lib_periode
= texte4
51 WHERE code_etat
= 'ICG'
55 -- activer pour génération des états PDF
56 -- SELECT @publication = 'oui'
58 CREATE TABLE #
cumul_ecritures (
68 IF ltrim(rtrim(@code
)) = '1-AUF' BEGIN
71 INSERT INTO #cumul_ecritures
80 FROM oas_balance
, oas_grplist g
82 oas_balance.cmpcode
= 'AUF'
84 (yr
= @exercice
AND period
BETWEEN 1 AND @periode
)
85 OR (yr
= @exercice
-1 AND period
BETWEEN 1 AND @periode
)
90 AND balcode
IN ('BUDGET','BUDGET-MENS','REEL')
91 AND oas_balance.el3
= g.code
92 AND g.grpcode
LIKE 'I%'
97 IF ( ltrim(rtrim(@code
)) = '3-GRB') BEGIN
99 INSERT INTO #cumul_ecritures
112 SELECT DISTINCT codbur
, bur
113 FROM auf_v_gen_implantations
118 (b.yr
= @exercice
AND b.period
BETWEEN 1 AND @periode
)
119 OR (b.yr
= @exercice
-1 AND b.period
BETWEEN 1 AND @periode
)
121 AND b.curcode
= 'EUR'
123 AND b.full_value
<> 0
124 AND b.balcode
IN ('BUDGET','BUDGET-MENS','REEL')
126 AND g.grpcode
LIKE 'B%'
129 AND g.grpcode
= bureau.codbur
132 INSERT INTO #cumul_ecritures
133 SELECT 'Services centraux', 2004, 12, 'REEL', '61850', '4101KU', -23595.4800
136 IF (LEFT(LTRIM(@code
),1) = '4') BEGIN
137 -- état pour le Bureau @code
138 SELECT @code
= rtrim(substring(ltrim(@code
),3,5))
140 INSERT INTO #cumul_ecritures
141 SELECT bur
, yr
, period
, balcode
, el1
, el3
, full_value
146 SELECT DISTINCT codbur
, bur
147 FROM auf_v_gen_implantations
152 (b.yr
= @exercice
AND b.period
BETWEEN 1 AND @periode
)
153 OR (b.yr
= @exercice
-1 AND b.period
BETWEEN 1 AND @periode
)
155 AND b.curcode
= 'EUR'
157 AND b.full_value
<> 0
158 AND b.balcode
IN ('BUDGET','BUDGET-MENS','REEL')
160 AND g.grpcode
= @code
163 AND g.grpcode
= bureau.codbur
165 IF (@code
= 'BSC' AND ( @exercice
= 2004 OR @exercice
= 2005))
166 INSERT INTO #cumul_ecritures
167 SELECT 'Services centraux', 2004, 12, 'REEL', '61850', '4101KU', -23595.4800
170 IF (LTRIM(RTRIM(@code
)) = '2-GRI') BEGIN
172 -- groupé par Implantation
173 INSERT INTO #cumul_ecritures
176 WHEN bureau.codbur
= 'BAN' THEN 'BA' + '-'+ bureau.
name
177 ELSE bureau.codbur
+ '-'+ bureau.
name
188 auf_v_gen_implantations bureau
192 (b.yr
= @exercice
AND b.period
BETWEEN 1 AND @periode
)
193 OR (b.yr
= @exercice
-1 AND b.period
BETWEEN 1 AND @periode
)
195 AND b.curcode
= 'EUR'
197 AND b.full_value
<> 0
198 AND b.balcode
in ('BUDGET', 'BUDGET-MENS', 'REEL')
200 AND g.grpcode
LIKE 'I%'
203 AND bureau.code
= right(rtrim(g.grpcode
),3)
205 IF (@exercice
= 2004 OR @exercice
= 2005)
206 INSERT INTO #cumul_ecritures
207 SELECT 'Centrale Paris', 2004, 12, 'REEL', '61850', '4101KU', -23595.4800
210 IF (LEFT(ltrim(@code
),1) = '5') BEGIN
212 -- pour l'implantation @code
213 SELECT @code
= rtrim(substring(ltrim(@code
),3,3))
215 INSERT INTO #cumul_ecritures
227 auf_v_gen_implantations bureau
231 (b.yr
= @exercice
AND b.period
BETWEEN 1 AND @periode
)
232 OR (b.yr
= @exercice
-1 AND b.period
BETWEEN 1 AND @periode
)
234 AND b.curcode
= 'EUR'
236 AND b.full_value
<> 0
237 AND b.balcode
in ('BUDGET','BUDGET-MENS','REEL')
239 AND g.grpcode
= 'I'+@code
242 AND bureau.code
= @code
244 IF (@code
= 'FR1' AND ( @exercice
= 2004 OR @exercice
= 2005 ))
245 INSERT INTO #cumul_ecritures
246 SELECT 'Centrale Paris', 2004, 12, 'REEL','61850','4101KU',-23595.4800
249 CREATE TABLE #
etat_section (
262 INSERT INTO #etat_section
268 '010-Excédents des produits (charges) avant retraitements' AS groupe1
,
269 '000-PRODUITS' AS groupe2
,
270 b.full_value
* -1 AS solde
, -- Corriger pour debit / crédit !!!!!!!!!!
273 b.el1
IN ('75100', '70500')
276 ) THEN '110-Ressources propres'
277 WHEN b.el1
LIKE '740%' THEN '120-Contributions gouvernementales'
278 WHEN b.el1
LIKE '745%' THEN '130-Contributions contractuelles'
284 AND rtrim(ltrim(el3
)) <> ''
286 '90003GR', '91022GR', '91203GR',
287 '91024GR','91025GR','91032GR', '9003GR', '9122GR', '9123GR',
288 '9124GR','9125GR','9132GR'
292 '91022GR', '91024GR', '91023GR', '91032GR','91025GR', '9122GR',
293 '9124GR', '9123GR', '9132GR','9125GR'
295 ) THEN '140-Apports, autres recettes, provisions'
299 ) THEN '150-Produits financiers et exceptionnels'
300 WHEN b.el1
LIKE '87%' THEN '160-Valeurs des biens et services à titre gratuit'
302 FROM #cumul_ecritures b
303 WHERE -- Filtres globaux
309 AND rtrim(ltrim(el3
)) <> ''
311 '90003GR', '91022GR', '91023GR', '91024GR','9125GR','9132GR',
312 '9003GR', '9122GR', '9123GR', '9124GR','9125GR','9132GR'
316 '91022GR', '91024GR', '91023GR', '91032GR','91025GR', '9122GR',
317 '9124GR', '9123GR', '9132GR','9125GR'
324 INSERT INTO #etat_section
330 '010-Excédents des produits (charges) avant retraitements' AS groupe1
,
331 '001-CHARGES' AS groupe2
,
332 b.full_value
* -1 AS solde
,
334 -- Attention séquence
335 WHEN b.el1
LIKE '861%' THEN '190-Valeurs des biens et services à titre gratuit'
336 WHEN grp1.grpcode
= 'HX' OR grpG.grpcode
= 'GX' THEN
337 -- Attention séquence
339 WHEN b.el3
LIKE '95%' THEN '010-Frais de personnel'
340 WHEN b.el3
LIKE '96%' THEN '020-Frais généraux'
343 AND (b.el3
LIKE '99099%' OR b.el3
LIKE '9999%')
344 THEN '120-Actions Réserve'
347 AND (b.el3
LIKE '91006%' OR b.el3
LIKE '9106%')
348 THEN '180-Perte (gain) de change'
351 OR b.el3
LIKE '9106%'
352 THEN '160-Charges financières'
356 AND (b.el3
LIKE '91007%' OR b.el3
LIKE '9107%')
357 THEN '170-Charges exceptionnelles'
358 ELSE '150-Autres charges, provisions'
360 WHEN grp1.grpcode
= 'H1' THEN '03A-' + space(8) + lg.
[name] + '-' + lg.code
361 WHEN grp1.grpcode
='H2' THEN '04B-' +space(8)+ lg.
[name]+'-'+lg.code
362 WHEN grp1.grpcode
='H3' THEN '05C-' +space(8)+ lg.
[name]+'-'+lg.code
363 WHEN grp1.grpcode
='H4' THEN '06D-' +space(8)+ lg.
[name]+'-'+lg.code
364 WHEN grp1.grpcode
='H5' THEN '07E-' +space(8)+ lg.
[name]+'-'+lg.code
365 WHEN grp1.grpcode
='H6' THEN '08V-' +space(8)+ lg.
[name]+'-'+lg.code
366 WHEN grp1.grpcode
='H7' THEN '09W-' +space(8)+ lg.
[name]+'-'+lg.code
367 WHEN grp1.grpcode
='H8' THEN '10X-' +space(8)+ lg.
[name]+'-'+lg.code
368 WHEN grpG.grpcode
='G1' THEN '03A-' +space(8)+ lg.
[name]
369 WHEN grpG.grpcode
='G2' THEN '04B-' +space(8)+ lg.
[name]
370 WHEN grpG.grpcode
='G3' THEN '05C-' +space(8)+ lg.
[name]
371 WHEN grpG.grpcode
='G4' THEN '06D-' +space(8)+ lg.
[name]
372 WHEN grpG.grpcode
='G5' THEN '07E-' +space(8)+ lg.
[name]
373 WHEN grpG.grpcode
='G6' THEN '08V-' +space(8)+ lg.
[name]
374 WHEN grp1.grpcode
='H0' OR grpG.grpcode
='G0' THEN '130-Actions institutionnelles'
375 WHEN grp1.grpcode
='HS' OR grpG.grpcode
='GS' THEN '140-Actions administratives'
380 LEFT OUTER JOIN oas_grplist grp1
381 ON grp1.grpcode
LIKE 'H%'
382 AND grp1.elmlevel
= 3
383 AND grp1.cmpcode
= 'AUF'
384 AND b.el3
= grp1.code
385 LEFT OUTER JOIN oas_grplist grp2
386 ON grp2.grpcode
LIKE 'L%'
387 AND grp2.elmlevel
= 3
388 AND grp2.cmpcode
= 'AUF'
389 AND b.el3
= grp2.code
390 LEFT OUTER JOIN oas_grplist grpG
391 ON grpG.grpcode
LIKE 'G%'
392 AND grpG.elmlevel
= 3
393 AND grpG.cmpcode
= 'AUF'
394 AND b.el3
= grpG.code
395 WHERE -- Filtres globaux
403 AND b.el1
NOT LIKE '96%'
404 AND b.el1
NOT LIKE '97%'
405 AND b.el1
NOT LIKE '98%'
407 '91022GR', '91023GR', '91024GR', '91032GR','91025GR', '9122GR',
408 '9123GR', '9124GR', '9132GR','9125GR'
412 AND rtrim(ltrim(el3
)) <> ''
414 '90003GR', '91022GR', '91023GR', '91024GR','91025GR','91032GR',
415 '9003GR', '9122GR', '9123GR', '9124GR','9125GR','9132GR'
418 AND b.el3
NOT LIKE '91009%'
419 AND b.el3
NOT LIKE '9109%'
420 AND (grp2.grpcode
= lg.code
OR grpG.grpcode
= lg.code
)
422 AND lg.cmpcode
= 'AUF'
423 AND b.el3
NOT LIKE '91008%'
424 AND b.el3
NOT LIKE '9108%'
427 -- section RETRAITEMENTS
428 -- mettre @publication <> 'oui' dans prod
430 IF @retraitement
= 'Oui' BEGIN
431 INSERT INTO #etat_section
438 '002-RETRAITEMENTS' AS groupe2
,
440 WHEN (el1
LIKE '6%' AND el3
!= '9003GR') OR el1
LIKE '77200' THEN full_value
*-1
445 (el1
LIKE '11%' AND el3
<> '')
446 AND NOT (el1
LIKE '11%' AND el3
IN ('90003GR', '91031GR', '91025GR'))
447 THEN '510-Moins : apports'
448 WHEN el1
LIKE '2%' THEN '020-Plus : investissements en immobilisations'
450 el3
IN ('90003GR', '91031GR', '91025GR')
451 THEN '010-Plus : affectation AG et au fonds de réserve'
452 WHEN el1
LIKE '16%' THEN '030-Plus : remboursement de la dette à long terme'
453 ELSE '550-Moins : amortis. immob. et pertes sur disposition'
455 FROM #cumul_ecritures
456 WHERE -- Filtres globaux
458 (el1
= '67500' AND el3
LIKE '91008%')
463 OR (el1
= '77200' AND el3
LIKE '91008%')
465 AND el1
NOT LIKE '28%'
466 AND el1
NOT LIKE '96%'
467 AND el1
NOT LIKE '97%'
468 AND el1
NOT LIKE '98%'
469 AND NOT ( el1
LIKE '2%' AND el3
LIKE '91008%' )
470 AND NOT ( el1
= '21820' AND el3
LIKE '91%')
471 AND NOT ( el1
= '68114' AND el3
LIKE '96%')
472 AND el3
NOT LIKE '91009%'
473 AND NOT ( el3
= '91033GR' AND yr
=2005 )
477 imp_bur
in ('BXX','IXX1') AND
480 AND NOT ( el1
= '67500' AND ( el3
LIKE '96%' OR el3
='30040QI'))
483 -- construire les colonne de l'état du résultats IWR
485 IF (ltrim(rtrim(@code
)) = '1-AUF')
486 -- si catégorie d'état = global AUF
487 UPDATE #etat_section
SET imp_bur
= ''
490 @categorie categorie
,
499 WHEN Sec.sgroupe
= '002-RETRAITEMENTS' THEN 0
500 ELSE ISNULL(budget.budget
,0)
501 END AS budget
, -- (1)
502 ISNULL(budget_mens.mensuel
,0) AS mensuel
, -- (2)
505 budget.budget
IS NULL OR
507 budget_mens.mensuel
IS NULL
510 CONVERT(numeric(18,5),budget_mens.mensuel
)/ CONVERT(numeric(18,5),budget.budget
)
511 -- budget_mens.mensuel/budget.budget
512 END AS pourc_mens
, -- (2)/(1)
513 ISNULL(reel_cour.reel
,0) reel
, -- (3)
514 ISNULL(reel_cumul.reel_cumul
,0) AS reel_cumul
, -- (4)
517 budget.budget
IS NULL
519 OR reel_cumul.reel_cumul
IS NULL
521 ELSE CONVERT(numeric(18,5),reel_cumul.reel_cumul
)/ CONVERT(numeric(18,5),budget.budget
)
522 END AS pourc_r_cour
, -- (4)/(1)
523 ISNULL(budget_mens.mensuel
,0)- isnull(reel_cumul.reel_cumul
,0) AS ecart_planif
, -- (2)-(4)
525 WHEN Sec.sgroupe
= '002-RETRAITEMENTS' THEN 0
526 ELSE ISNULL(budget.budget
,0)- isnull(reel_cumul.reel_cumul
,0)
527 END AS solde_total
, --(1)-(4)
529 WHEN Sec.sgroupe
= '002-RETRAITEMENTS' THEN 0
530 WHEN ( budget.budget
IS NULL OR budget.budget
= 0 ) THEN 0
532 CONVERT(numeric(18,5),(budget.budget
- ISNULL(reel_cumul.reel_cumul
,0))) /
533 CONVERT(numeric(18,5),budget.budget
)
534 END AS pourc_r_total
, -- [(1)-(4)]/(1)
535 ISNULL(budget_dern.budget_dern
,0) budget_dern
, -- (5)
536 ISNULL(reel_dern.reel_dern
,0) reel_dern
, -- (6)
539 budget_dern.budget_dern
IS NULL
540 OR budget_dern.budget_dern
= 0
541 OR reel_dern.reel_dern
IS NULL
544 CONVERT(numeric(18,5),reel_dern.reel_dern
) /
545 CONVERT(numeric(18,5),budget_dern.budget_dern
)
546 END AS pourc_r_dern
-- (6)/(5)
550 SELECT DISTINCT imp_bur
, groupe
, sgroupe
, libelle
554 -- budget année en cours
556 SELECT imp_bur
, sgroupe
, libelle
, SUM(montant
) budget
558 WHERE exercice
= @exercice
AND cumul
= 'BUDGET'
559 GROUP BY imp_bur
, sgroupe
, libelle
561 ON sec.imp_bur
= budget.imp_bur
562 AND sec.sgroupe
= budget.sgroupe
563 AND sec.libelle
= budget.libelle
565 -- planification mensuel
567 SELECT imp_bur
, sgroupe
, libelle
, SUM(montant
) mensuel
569 WHERE exercice
= @exercice
AND cumul
= 'BUDGET-MENS'
570 GROUP BY imp_bur
, sgroupe
, libelle
572 ON sec.imp_bur
= budget_mens.imp_bur
573 AND sec.sgroupe
= budget_mens.sgroupe
574 AND sec.libelle
= budget_mens.libelle
576 -- budget réalisé période en cours
578 SELECT imp_bur
, sgroupe
, libelle
, SUM(montant
) reel
580 WHERE exercice
= @exercice
AND periode
= @periode
AND cumul
= 'REEL'
581 GROUP BY imp_bur
, sgroupe
, libelle
583 ON sec.imp_bur
= reel_cour.imp_bur
584 AND sec.sgroupe
= reel_cour.sgroupe
585 AND sec.libelle
= reel_cour.libelle
587 -- budget réalisé cumulé en cours
589 SELECT imp_bur
, sgroupe
, libelle
, SUM(montant
) reel_cumul
591 WHERE exercice
= @exercice
AND cumul
= 'REEL'
592 GROUP BY imp_bur
, sgroupe
, libelle
594 ON sec.imp_bur
= reel_cumul.imp_bur
595 AND sec.sgroupe
= reel_cumul.sgroupe
596 AND sec.libelle
= reel_cumul.libelle
598 -- budget année dernière
600 SELECT imp_bur
, sgroupe
, libelle
, SUM(montant
) budget_dern
602 WHERE exercice
= @exercice
-1 AND cumul
= 'BUDGET'
603 GROUP BY imp_bur
, sgroupe
, libelle
605 ON sec.imp_bur
= budget_dern.imp_bur
606 AND sec.sgroupe
= budget_dern.sgroupe
607 AND sec.libelle
= budget_dern.libelle
609 -- réalisé cumulé année dernière
611 SELECT imp_bur
, sgroupe
, libelle
, SUM(montant
) reel_dern
613 WHERE exercice
= @exercice
-1 AND cumul
= 'REEL' AND periode
<= @periode
614 GROUP BY imp_bur
, sgroupe
, libelle
616 ON sec.imp_bur
= reel_dern.imp_bur
617 AND sec.sgroupe
= reel_dern.sgroupe
618 AND sec.libelle
= reel_dern.libelle
623 categorie
, exercice execice
, titre
, periode
, imp_bur
, groupe
, sgroupe
,
624 libelle
, budget
, mensuel
, pourc_mens
, reel
, reel_cumul
, pourc_r_cour
,
625 ecart_planif
, solde_total
, pourc_r_total
, budget_dern
, reel_dern
,
630 categorie
, exercice
, titre
, periode
, imp_bur
, groupe
, sgroupe
, libelle
,
631 budget
, mensuel
, pourc_mens
, reel
, reel_cumul
, pourc_r_cour
,
632 ecart_planif
, solde_total
, pourc_r_total
, budget_dern
, reel_dern
,
645 WHEN substring(libelle
,3,1) = 'A' THEN '031-Projets institutnnels des établismts'
646 WHEN substring(libelle
,3,1) = 'B' THEN '041-Renforcemt capacités des établismts'
647 WHEN substring(libelle
,3,1) = 'C' THEN '051-Renforcemt coopération scientifique'
648 WHEN substring(libelle
,3,1) = 'D' THEN '061-Langue Fr et dévlpmt Francophonie'
649 WHEN substring(libelle
,3,1) = 'E' THEN '071-Coop univ pour form° et/ou recherche'
650 WHEN substring(libelle
,3,1) = 'V' THEN '081-Valo ressources pédagogiques et sc'
651 WHEN substring(libelle
,3,1) = 'W' THEN '091-Renforcmt capacités individuelles'
652 WHEN substring(libelle
,3,1) = 'X' THEN '101-Valo bénéficiaires Intégration pro'
655 SUM(mensuel
) mensuel
,
658 SUM(budget
) IS NULL OR SUM(budget
) = 0 OR SUM(mensuel
) IS NULL
660 ELSE CONVERT(numeric(18,5),SUM(mensuel
))/ CONVERT(numeric(18,5),SUM(budget
))
661 END AS pourc_mens
, -- (2)/(1)
663 SUM(reel_cumul
) reel_cumul
,
666 SUM(budget
) IS NULL OR SUM(budget
) = 0 OR SUM(reel_cumul
) IS NULL
668 ELSE CONVERT(numeric(18,5),SUM(reel_cumul
))/ CONVERT(numeric(18,5),SUM(budget
))
669 END AS pourc_r_cour
, -- (4)/(1)
670 SUM(ecart_planif
) ecart_planif
,
671 SUM(solde_total
) solde_total
,
673 WHEN sgroupe
= '002-RETRAITEMENTS' THEN 0
674 WHEN SUM(budget
) IS NULL OR SUM(budget
) = 0 THEN 0
676 CONVERT(numeric(18,5),(SUM(budget
)- ISNULL(SUM(reel_cumul
),0))) /
677 CONVERT(numeric(18,5),SUM(budget
))
678 END AS pourc_r_total
, -- [(1)-(4)]/(1)
679 SUM(budget_dern
) budget_dern
,
680 SUM(reel_dern
) reel_dern
,
683 SUM(budget_dern
) IS NULL OR SUM(budget_dern
) = 0 OR SUM(reel_dern
) IS NULL
686 CONVERT(numeric(18,5),SUM(reel_dern
)) /
687 CONVERT(numeric(18,5),SUM(budget_dern
))
688 END AS pourc_r_dern
-- (6)/(5)
690 WHERE substring(libelle
,3,1) in ('A','B','C','D','E','V', 'W', 'X')
700 WHEN substring(libelle
,3,1) = 'A' THEN '031-Projets institutnnels des établismts'
701 WHEN substring(libelle
,3,1) = 'B' THEN '041-Renforcemt capacités des établismts'
702 WHEN substring(libelle
,3,1) = 'C' THEN '051-Renforcemt coopération scientifique'
703 WHEN substring(libelle
,3,1) = 'D' THEN '061-Langue Fr et dévlpmt Francophonie'
704 WHEN substring(libelle
,3,1) = 'E' THEN '071-Coop univ pour form° et/ou recherche'
705 WHEN substring(libelle
,3,1) = 'V' THEN '081-Valo ressources pédagogiques et sc'
706 WHEN substring(libelle
,3,1) = 'W' THEN '091-Renforcmt capacités individuelles'
707 WHEN substring(libelle
,3,1) = 'X' THEN '101-Valo bénéficiaires Intégration pro'
719 WHEN sgroupe
='000-PRODUITS' THEN '151-Total des produits hors BSTG'
720 ELSE '181-Total des charges hors BSTG'
723 SUM(mensuel
) mensuel
,
725 WHEN SUM(budget
) IS NULL OR SUM(budget
) = 0 OR SUM(mensuel
) IS NULL THEN 0
726 ELSE CONVERT(numeric(18,5),SUM(mensuel
))/ CONVERT(numeric(18,5),SUM(budget
))
727 END AS pourc_mens
, -- (2)/(1)
729 SUM(reel_cumul
) reel_cumul
,
731 WHEN SUM(budget
) IS NULL OR SUM(budget
) = 0 OR SUM(reel_cumul
) IS NULL THEN 0
732 ELSE CONVERT(numeric(18,5),SUM(reel_cumul
))/ CONVERT(numeric(18,5),SUM(budget
))
733 END AS pourc_r_cour
, -- (4)/(1)
734 SUM(ecart_planif
) ecart_planif
,
735 SUM(solde_total
) solde_total
,
737 WHEN SUM(budget
) IS NULL OR SUM(budget
) = 0 THEN 0
739 CONVERT(numeric(18,5),(SUM(budget
)- ISNULL(SUM(reel_cumul
),0))) /
740 CONVERT(numeric(18,5),SUM(budget
))
741 END AS pourc_r_total
, -- [(1)-(4)]/(1)
742 SUM(budget_dern
) budget_dern
,
743 SUM(reel_dern
) reel_dern
,
746 SUM(budget_dern
) IS NULL OR SUM(budget_dern
) = 0 OR SUM(reel_dern
) IS NULL
749 CONVERT(numeric(18,5),SUM(reel_dern
)) /
750 CONVERT(numeric(18,5),SUM(budget_dern
))
751 END AS pourc_r_dern
-- (6)/(5)
754 sgroupe
IN ( '000-PRODUITS','001-CHARGES')
755 AND NOT ( sgroupe
= '000-PRODUITS' AND substring(libelle
,1,3) = '160')
756 AND NOT ( sgroupe
= '001-CHARGES' AND substring(libelle
,1,3) = '190')
766 WHEN sgroupe
='000-PRODUITS' THEN '151-Total des produits hors BSTG'
767 ELSE '181-Total des charges hors BSTG'
778 '021-Actions des programmes' AS libelle
,
780 SUM(mensuel
) mensuel
,
782 WHEN SUM(budget
) IS NULL OR SUM(budget
) = 0 OR SUM(mensuel
) IS NULL THEN 0
783 ELSE CONVERT(numeric(18,5),SUM(mensuel
))/ CONVERT(numeric(18,5),SUM(budget
))
784 END AS pourc_mens
, -- (2)/(1)
786 SUM(reel_cumul
) reel_cumul
,
788 WHEN SUM(budget
) IS NULL OR SUM(budget
) = 0 OR SUM(reel_cumul
) IS NULL THEN 0
789 ELSE CONVERT(numeric(18,5),SUM(reel_cumul
))/ CONVERT(numeric(18,5),SUM(budget
))
790 END AS pourc_r_cour
, -- (4)/(1)
791 SUM(ecart_planif
) ecart_planif
,
792 SUM(solde_total
) solde_total
,
794 WHEN SUM(budget
) IS NULL OR SUM(budget
) = 0 THEN 0
796 CONVERT(numeric(18,5),(SUM(budget
)- ISNULL(SUM(reel_cumul
),0))) /
797 CONVERT(numeric(18,5),SUM(budget
))
798 END AS pourc_r_total
, -- [(1)-(4)]/(1)
799 SUM(budget_dern
) budget_dern
,
800 SUM(reel_dern
) reel_dern
,
803 SUM(budget_dern
) IS NULL OR SUM(budget_dern
) = 0 OR SUM(reel_dern
) IS NULL
806 CONVERT(numeric(18,5),SUM(reel_dern
))/ CONVERT(numeric(18,5),SUM(budget_dern
))
807 END AS pourc_r_dern
-- (6)/(5)
810 sgroupe
= '001-CHARGES'
811 AND substring(libelle
,3,1) in ('A','B','C','D','E','V', 'W', 'X')
812 GROUP BY categorie
, exercice
, titre
, periode
, imp_bur
, groupe
, sgroupe
818 WHEN LEFT(r.libelle
,2) IN ('03','04','05','06','07','08', '09', '10') THEN 0
819 WHEN LEFT(r.libelle
,3) IN ('151','181') THEN 0
823 ORDER BY imp_bur
,groupe
,sgroupe
,libelle
,reel_dern
825 DROP TABLE #etat_section
826 DROP TABLE #cumul_ecritures