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'
281 THEN '130-Contributions contractuelles'
287 AND rtrim(ltrim(el3
)) <> ''
289 '90003GR', '91022GR', '91203GR',
290 '91024GR','91025GR','91032GR', '9003GR', '9122GR', '9123GR',
291 '9124GR','9125GR','9132GR'
295 '91022GR', '91024GR', '91023GR', '91032GR','91025GR', '9122GR',
296 '9124GR', '9123GR', '9132GR','9125GR'
298 THEN '140-Apports, autres recettes, provisions'
302 THEN '150-Produits financiers et exceptionnels'
303 WHEN b.el1
= '75800' THEN '160-Exploitation'
304 WHEN b.el1
LIKE '87%' THEN '170-Valeurs des biens et services à titre gratuit'
306 FROM #cumul_ecritures b
307 WHERE -- Filtres globaux
313 AND rtrim(ltrim(el3
)) <> ''
315 '90003GR', '91022GR', '91023GR', '91024GR','9125GR','9132GR',
316 '9003GR', '9122GR', '9123GR', '9124GR','9125GR','9132GR'
320 '91022GR', '91024GR', '91023GR', '91032GR','91025GR', '9122GR',
321 '9124GR', '9123GR', '9132GR','9125GR'
328 INSERT INTO #etat_section
334 '010-Excédents des produits (charges) avant retraitements' AS groupe1
,
335 '001-CHARGES' AS groupe2
,
336 b.full_value
* -1 AS solde
,
338 -- Attention séquence
339 WHEN b.el1
LIKE '861%' THEN '190-Valeurs des biens et services à titre gratuit'
340 WHEN grp1.grpcode
= 'HX' OR grpG.grpcode
= 'GX' THEN
341 -- Attention séquence
343 WHEN b.el3
LIKE '95%' THEN '010-Frais de personnel'
344 WHEN b.el3
LIKE '96%' THEN '020-Frais généraux'
347 AND (b.el3
LIKE '99099%' OR b.el3
LIKE '9999%')
348 THEN '120-Actions Réserve'
351 AND (b.el3
LIKE '91006%' OR b.el3
LIKE '9106%')
352 THEN '180-Perte (gain) de change'
355 OR b.el3
LIKE '9106%'
356 THEN '160-Charges financières'
360 AND (b.el3
LIKE '91007%' OR b.el3
LIKE '9107%')
361 THEN '170-Charges exceptionnelles'
364 AND b.el3
LIKE '91002GR%'
365 THEN '155-Charges cotisations'
366 ELSE '150-Autres charges, provisions'
368 WHEN grp1.grpcode
= 'H1' THEN '03A-' + space(8) + lg.
[name] + '-' + lg.code
369 WHEN grp1.grpcode
='H2' THEN '04B-' +space(8)+ lg.
[name]+'-'+lg.code
370 WHEN grp1.grpcode
='H3' THEN '05C-' +space(8)+ lg.
[name]+'-'+lg.code
371 WHEN grp1.grpcode
='H4' THEN '06D-' +space(8)+ lg.
[name]+'-'+lg.code
372 WHEN grp1.grpcode
='H5' THEN '07E-' +space(8)+ lg.
[name]+'-'+lg.code
373 WHEN grp1.grpcode
='H6' THEN '08V-' +space(8)+ lg.
[name]+'-'+lg.code
374 WHEN grp1.grpcode
='H7' THEN '09W-' +space(8)+ lg.
[name]+'-'+lg.code
375 WHEN grp1.grpcode
='H8' THEN '10X-' +space(8)+ lg.
[name]+'-'+lg.code
376 WHEN grpG.grpcode
='G1' THEN '03A-' +space(8)+ lg.
[name]
377 WHEN grpG.grpcode
='G2' THEN '04B-' +space(8)+ lg.
[name]
378 WHEN grpG.grpcode
='G3' THEN '05C-' +space(8)+ lg.
[name]
379 WHEN grpG.grpcode
='G4' THEN '06D-' +space(8)+ lg.
[name]
380 WHEN grpG.grpcode
='G5' THEN '07E-' +space(8)+ lg.
[name]
381 WHEN grpG.grpcode
='G6' THEN '08V-' +space(8)+ lg.
[name]
382 WHEN grp1.grpcode
='H0' OR grpG.grpcode
='G0' THEN '130-Actions institutionnelles'
383 WHEN grp1.grpcode
='HS' OR grpG.grpcode
='GS' THEN '140-Actions administratives'
388 LEFT OUTER JOIN oas_grplist grp1
389 ON grp1.grpcode
LIKE 'H%'
390 AND grp1.elmlevel
= 3
391 AND grp1.cmpcode
= 'AUF'
392 AND b.el3
= grp1.code
393 LEFT OUTER JOIN oas_grplist grp2
394 ON grp2.grpcode
LIKE 'L%'
395 AND grp2.elmlevel
= 3
396 AND grp2.cmpcode
= 'AUF'
397 AND b.el3
= grp2.code
398 LEFT OUTER JOIN oas_grplist grpG
399 ON grpG.grpcode
LIKE 'G%'
400 AND grpG.elmlevel
= 3
401 AND grpG.cmpcode
= 'AUF'
402 AND b.el3
= grpG.code
403 WHERE -- Filtres globaux
411 AND b.el1
NOT LIKE '96%'
412 AND b.el1
NOT LIKE '97%'
413 AND b.el1
NOT LIKE '98%'
415 '91022GR', '91023GR', '91024GR', '91032GR','91025GR', '9122GR',
416 '9123GR', '9124GR', '9132GR','9125GR'
420 AND rtrim(ltrim(el3
)) <> ''
422 '90003GR', '91022GR', '91023GR', '91024GR','91025GR','91032GR',
423 '9003GR', '9122GR', '9123GR', '9124GR','9125GR','9132GR'
426 AND b.el3
NOT LIKE '91009%'
427 AND b.el3
NOT LIKE '9109%'
428 AND (grp2.grpcode
= lg.code
OR grpG.grpcode
= lg.code
)
430 AND lg.cmpcode
= 'AUF'
431 AND b.el3
NOT LIKE '91008%'
432 AND b.el3
NOT LIKE '9108%'
435 -- section RETRAITEMENTS
436 -- mettre @publication <> 'oui' dans prod
438 IF @retraitement
= 'Oui' BEGIN
439 INSERT INTO #etat_section
446 '002-RETRAITEMENTS' AS groupe2
,
448 WHEN (el1
LIKE '6%' AND el3
!= '9003GR') OR el1
LIKE '77200' THEN full_value
*-1
453 (el1
LIKE '11%' AND el3
<> '')
454 AND NOT (el1
LIKE '11%' AND el3
IN ('90003GR', '91031GR', '91025GR'))
455 THEN '510-Moins : apports'
456 WHEN el1
LIKE '2%' THEN '020-Plus : investissements en immobilisations'
458 el3
IN ('90003GR', '91031GR', '91025GR')
459 THEN '010-Plus : affectation AG et au fonds de réserve'
460 WHEN el1
LIKE '16%' THEN '030-Plus : remboursement de la dette à long terme'
461 ELSE '550-Moins : amortis. immob. et pertes sur disposition'
463 FROM #cumul_ecritures
464 WHERE -- Filtres globaux
466 (el1
= '67500' AND el3
LIKE '91008%')
471 OR (el1
= '77200' AND el3
LIKE '91008%')
473 AND el1
NOT LIKE '28%'
474 AND el1
NOT LIKE '96%'
475 AND el1
NOT LIKE '97%'
476 AND el1
NOT LIKE '98%'
477 AND NOT ( el1
LIKE '2%' AND el3
LIKE '91008%' )
478 AND NOT ( el1
= '21820' AND el3
LIKE '91%')
479 AND NOT ( el1
= '68114' AND el3
LIKE '96%')
480 AND el3
NOT LIKE '91009%'
481 AND NOT ( el3
= '91033GR' AND yr
=2005 )
485 imp_bur
in ('BXX','IXX1') AND
488 AND NOT ( el1
= '67500' AND ( el3
LIKE '96%' OR el3
='30040QI'))
491 -- construire les colonne de l'état du résultats IWR
493 IF (ltrim(rtrim(@code
)) = '1-AUF')
494 -- si catégorie d'état = global AUF
495 UPDATE #etat_section
SET imp_bur
= ''
498 @categorie categorie
,
507 WHEN Sec.sgroupe
= '002-RETRAITEMENTS' THEN 0
508 ELSE ISNULL(budget.budget
,0)
509 END AS budget
, -- (1)
510 ISNULL(budget_mens.mensuel
,0) AS mensuel
, -- (2)
513 budget.budget
IS NULL OR
515 budget_mens.mensuel
IS NULL
518 CONVERT(numeric(18,5),budget_mens.mensuel
)/ CONVERT(numeric(18,5),budget.budget
)
519 -- budget_mens.mensuel/budget.budget
520 END AS pourc_mens
, -- (2)/(1)
521 ISNULL(reel_cour.reel
,0) reel
, -- (3)
522 ISNULL(reel_cumul.reel_cumul
,0) AS reel_cumul
, -- (4)
525 budget.budget
IS NULL
527 OR reel_cumul.reel_cumul
IS NULL
529 ELSE CONVERT(numeric(18,5),reel_cumul.reel_cumul
)/ CONVERT(numeric(18,5),budget.budget
)
530 END AS pourc_r_cour
, -- (4)/(1)
531 ISNULL(budget_mens.mensuel
,0)- isnull(reel_cumul.reel_cumul
,0) AS ecart_planif
, -- (2)-(4)
533 WHEN Sec.sgroupe
= '002-RETRAITEMENTS' THEN 0
534 ELSE ISNULL(budget.budget
,0)- isnull(reel_cumul.reel_cumul
,0)
535 END AS solde_total
, --(1)-(4)
537 WHEN Sec.sgroupe
= '002-RETRAITEMENTS' THEN 0
538 WHEN ( budget.budget
IS NULL OR budget.budget
= 0 ) THEN 0
540 CONVERT(numeric(18,5),(budget.budget
- ISNULL(reel_cumul.reel_cumul
,0))) /
541 CONVERT(numeric(18,5),budget.budget
)
542 END AS pourc_r_total
, -- [(1)-(4)]/(1)
543 ISNULL(budget_dern.budget_dern
,0) budget_dern
, -- (5)
544 ISNULL(reel_dern.reel_dern
,0) reel_dern
, -- (6)
547 budget_dern.budget_dern
IS NULL
548 OR budget_dern.budget_dern
= 0
549 OR reel_dern.reel_dern
IS NULL
552 CONVERT(numeric(18,5),reel_dern.reel_dern
) /
553 CONVERT(numeric(18,5),budget_dern.budget_dern
)
554 END AS pourc_r_dern
-- (6)/(5)
558 SELECT DISTINCT imp_bur
, groupe
, sgroupe
, libelle
562 -- budget année en cours
564 SELECT imp_bur
, sgroupe
, libelle
, SUM(montant
) budget
566 WHERE exercice
= @exercice
AND cumul
= 'BUDGET'
567 GROUP BY imp_bur
, sgroupe
, libelle
569 ON sec.imp_bur
= budget.imp_bur
570 AND sec.sgroupe
= budget.sgroupe
571 AND sec.libelle
= budget.libelle
573 -- planification mensuel
575 SELECT imp_bur
, sgroupe
, libelle
, SUM(montant
) mensuel
577 WHERE exercice
= @exercice
AND cumul
= 'BUDGET-MENS'
578 GROUP BY imp_bur
, sgroupe
, libelle
580 ON sec.imp_bur
= budget_mens.imp_bur
581 AND sec.sgroupe
= budget_mens.sgroupe
582 AND sec.libelle
= budget_mens.libelle
584 -- budget réalisé période en cours
586 SELECT imp_bur
, sgroupe
, libelle
, SUM(montant
) reel
588 WHERE exercice
= @exercice
AND periode
= @periode
AND cumul
= 'REEL'
589 GROUP BY imp_bur
, sgroupe
, libelle
591 ON sec.imp_bur
= reel_cour.imp_bur
592 AND sec.sgroupe
= reel_cour.sgroupe
593 AND sec.libelle
= reel_cour.libelle
595 -- budget réalisé cumulé en cours
597 SELECT imp_bur
, sgroupe
, libelle
, SUM(montant
) reel_cumul
599 WHERE exercice
= @exercice
AND cumul
= 'REEL'
600 GROUP BY imp_bur
, sgroupe
, libelle
602 ON sec.imp_bur
= reel_cumul.imp_bur
603 AND sec.sgroupe
= reel_cumul.sgroupe
604 AND sec.libelle
= reel_cumul.libelle
606 -- budget année dernière
608 SELECT imp_bur
, sgroupe
, libelle
, SUM(montant
) budget_dern
610 WHERE exercice
= @exercice
-1 AND cumul
= 'BUDGET'
611 GROUP BY imp_bur
, sgroupe
, libelle
613 ON sec.imp_bur
= budget_dern.imp_bur
614 AND sec.sgroupe
= budget_dern.sgroupe
615 AND sec.libelle
= budget_dern.libelle
617 -- réalisé cumulé année dernière
619 SELECT imp_bur
, sgroupe
, libelle
, SUM(montant
) reel_dern
621 WHERE exercice
= @exercice
-1 AND cumul
= 'REEL' AND periode
<= @periode
622 GROUP BY imp_bur
, sgroupe
, libelle
624 ON sec.imp_bur
= reel_dern.imp_bur
625 AND sec.sgroupe
= reel_dern.sgroupe
626 AND sec.libelle
= reel_dern.libelle
631 categorie
, exercice execice
, titre
, periode
, imp_bur
, groupe
, sgroupe
,
632 libelle
, budget
, mensuel
, pourc_mens
, reel
, reel_cumul
, pourc_r_cour
,
633 ecart_planif
, solde_total
, pourc_r_total
, budget_dern
, reel_dern
,
638 categorie
, exercice
, titre
, periode
, imp_bur
, groupe
, sgroupe
, libelle
,
639 budget
, mensuel
, pourc_mens
, reel
, reel_cumul
, pourc_r_cour
,
640 ecart_planif
, solde_total
, pourc_r_total
, budget_dern
, reel_dern
,
653 WHEN substring(libelle
,3,1) = 'A' THEN '031-Projets institutnnels des établismts'
654 WHEN substring(libelle
,3,1) = 'B' THEN '041-Renforcemt capacités des établismts'
655 WHEN substring(libelle
,3,1) = 'C' THEN '051-Renforcemt coopération scientifique'
656 WHEN substring(libelle
,3,1) = 'D' THEN '061-Langue Fr et dévlpmt Francophonie'
657 WHEN substring(libelle
,3,1) = 'E' THEN '071-Coop univ pour form° et/ou recherche'
658 WHEN substring(libelle
,3,1) = 'V' THEN '081-Valo ressources pédagogiques et sc'
659 WHEN substring(libelle
,3,1) = 'W' THEN '091-Renforcmt capacités individuelles'
660 WHEN substring(libelle
,3,1) = 'X' THEN '101-Valo bénéficiaires Intégration pro'
663 SUM(mensuel
) mensuel
,
666 SUM(budget
) IS NULL OR SUM(budget
) = 0 OR SUM(mensuel
) IS NULL
668 ELSE CONVERT(numeric(18,5),SUM(mensuel
))/ CONVERT(numeric(18,5),SUM(budget
))
669 END AS pourc_mens
, -- (2)/(1)
671 SUM(reel_cumul
) reel_cumul
,
674 SUM(budget
) IS NULL OR SUM(budget
) = 0 OR SUM(reel_cumul
) IS NULL
676 ELSE CONVERT(numeric(18,5),SUM(reel_cumul
))/ CONVERT(numeric(18,5),SUM(budget
))
677 END AS pourc_r_cour
, -- (4)/(1)
678 SUM(ecart_planif
) ecart_planif
,
679 SUM(solde_total
) solde_total
,
681 WHEN sgroupe
= '002-RETRAITEMENTS' THEN 0
682 WHEN SUM(budget
) IS NULL OR SUM(budget
) = 0 THEN 0
684 CONVERT(numeric(18,5),(SUM(budget
)- ISNULL(SUM(reel_cumul
),0))) /
685 CONVERT(numeric(18,5),SUM(budget
))
686 END AS pourc_r_total
, -- [(1)-(4)]/(1)
687 SUM(budget_dern
) budget_dern
,
688 SUM(reel_dern
) reel_dern
,
691 SUM(budget_dern
) IS NULL OR SUM(budget_dern
) = 0 OR SUM(reel_dern
) IS NULL
694 CONVERT(numeric(18,5),SUM(reel_dern
)) /
695 CONVERT(numeric(18,5),SUM(budget_dern
))
696 END AS pourc_r_dern
-- (6)/(5)
698 WHERE substring(libelle
,3,1) in ('A','B','C','D','E','V', 'W', 'X')
708 WHEN substring(libelle
,3,1) = 'A' THEN '031-Projets institutnnels des établismts'
709 WHEN substring(libelle
,3,1) = 'B' THEN '041-Renforcemt capacités des établismts'
710 WHEN substring(libelle
,3,1) = 'C' THEN '051-Renforcemt coopération scientifique'
711 WHEN substring(libelle
,3,1) = 'D' THEN '061-Langue Fr et dévlpmt Francophonie'
712 WHEN substring(libelle
,3,1) = 'E' THEN '071-Coop univ pour form° et/ou recherche'
713 WHEN substring(libelle
,3,1) = 'V' THEN '081-Valo ressources pédagogiques et sc'
714 WHEN substring(libelle
,3,1) = 'W' THEN '091-Renforcmt capacités individuelles'
715 WHEN substring(libelle
,3,1) = 'X' THEN '101-Valo bénéficiaires Intégration pro'
727 WHEN sgroupe
='000-PRODUITS' THEN '151-Total des produits hors BSTG'
728 ELSE '181-Total des charges hors BSTG'
731 SUM(mensuel
) mensuel
,
733 WHEN SUM(budget
) IS NULL OR SUM(budget
) = 0 OR SUM(mensuel
) IS NULL THEN 0
734 ELSE CONVERT(numeric(18,5),SUM(mensuel
))/ CONVERT(numeric(18,5),SUM(budget
))
735 END AS pourc_mens
, -- (2)/(1)
737 SUM(reel_cumul
) reel_cumul
,
739 WHEN SUM(budget
) IS NULL OR SUM(budget
) = 0 OR SUM(reel_cumul
) IS NULL THEN 0
740 ELSE CONVERT(numeric(18,5),SUM(reel_cumul
))/ CONVERT(numeric(18,5),SUM(budget
))
741 END AS pourc_r_cour
, -- (4)/(1)
742 SUM(ecart_planif
) ecart_planif
,
743 SUM(solde_total
) solde_total
,
745 WHEN SUM(budget
) IS NULL OR SUM(budget
) = 0 THEN 0
747 CONVERT(numeric(18,5),(SUM(budget
)- ISNULL(SUM(reel_cumul
),0))) /
748 CONVERT(numeric(18,5),SUM(budget
))
749 END AS pourc_r_total
, -- [(1)-(4)]/(1)
750 SUM(budget_dern
) budget_dern
,
751 SUM(reel_dern
) reel_dern
,
754 SUM(budget_dern
) IS NULL OR SUM(budget_dern
) = 0 OR SUM(reel_dern
) IS NULL
757 CONVERT(numeric(18,5),SUM(reel_dern
)) /
758 CONVERT(numeric(18,5),SUM(budget_dern
))
759 END AS pourc_r_dern
-- (6)/(5)
762 sgroupe
IN ( '000-PRODUITS','001-CHARGES')
763 AND NOT ( sgroupe
= '000-PRODUITS' AND substring(libelle
,1,3) = '160')
764 AND NOT ( sgroupe
= '001-CHARGES' AND substring(libelle
,1,3) = '190')
774 WHEN sgroupe
='000-PRODUITS' THEN '151-Total des produits hors BSTG'
775 ELSE '181-Total des charges hors BSTG'
786 '021-Actions des programmes' AS libelle
,
788 SUM(mensuel
) mensuel
,
790 WHEN SUM(budget
) IS NULL OR SUM(budget
) = 0 OR SUM(mensuel
) IS NULL THEN 0
791 ELSE CONVERT(numeric(18,5),SUM(mensuel
))/ CONVERT(numeric(18,5),SUM(budget
))
792 END AS pourc_mens
, -- (2)/(1)
794 SUM(reel_cumul
) reel_cumul
,
796 WHEN SUM(budget
) IS NULL OR SUM(budget
) = 0 OR SUM(reel_cumul
) IS NULL THEN 0
797 ELSE CONVERT(numeric(18,5),SUM(reel_cumul
))/ CONVERT(numeric(18,5),SUM(budget
))
798 END AS pourc_r_cour
, -- (4)/(1)
799 SUM(ecart_planif
) ecart_planif
,
800 SUM(solde_total
) solde_total
,
802 WHEN SUM(budget
) IS NULL OR SUM(budget
) = 0 THEN 0
804 CONVERT(numeric(18,5),(SUM(budget
)- ISNULL(SUM(reel_cumul
),0))) /
805 CONVERT(numeric(18,5),SUM(budget
))
806 END AS pourc_r_total
, -- [(1)-(4)]/(1)
807 SUM(budget_dern
) budget_dern
,
808 SUM(reel_dern
) reel_dern
,
811 SUM(budget_dern
) IS NULL OR SUM(budget_dern
) = 0 OR SUM(reel_dern
) IS NULL
814 CONVERT(numeric(18,5),SUM(reel_dern
))/ CONVERT(numeric(18,5),SUM(budget_dern
))
815 END AS pourc_r_dern
-- (6)/(5)
818 sgroupe
= '001-CHARGES'
819 AND substring(libelle
,3,1) in ('A','B','C','D','E','V', 'W', 'X')
820 GROUP BY categorie
, exercice
, titre
, periode
, imp_bur
, groupe
, sgroupe
826 WHEN LEFT(r.libelle
,2) IN ('03','04','05','06','07','08', '09', '10') THEN 0
827 WHEN LEFT(r.libelle
,3) IN ('151','181') THEN 0
831 ORDER BY imp_bur
,groupe
,sgroupe
,libelle
,reel_dern
833 DROP TABLE #etat_section
834 DROP TABLE #cumul_ecritures