6 SET QUOTED_IDENTIFIER
OFF
9 ALTER PROCEDURE [dbo
].
[auf_p_intero_cumul_dep_rec
]
16 DECLARE @like_el3
varchar(20)
20 IF isnumeric(@projet
) = 1 OR len(@projet
) > 2
21 SELECT @like_el3
= @projet
+'%'
23 SELECT @like_el3
= '%'+@projet
25 CREATE TABLE #
cumuls (
27 typecumul
varchar(12) ,
35 'DEP-BUDGET' typecumul
,
37 FROM oas_balance
, oas_grplist imp
39 oas_balance.cmpcode
= 'AUF'
40 AND imp.cmpcode
= 'AUF'
42 AND period
BETWEEN 1 AND @periode
46 AND (el1
LIKE '2%' OR el1
LIKE '6%' OR el1
LIKE '9%')
47 -- on exclut les repartitions --
48 AND el1
NOT LIKE '96%'
49 AND el1
NOT LIKE '97%'
50 AND el1
NOT LIKE '98%'
51 AND el3
LIKE @like_el3
54 AND imp.grpcode
LIKE @groupe
63 FROM oas_balance
, oas_grplist imp
65 oas_balance.cmpcode
= 'AUF'
66 AND imp.cmpcode
= 'AUF'
68 AND period
BETWEEN 1 AND @periode
72 AND (el1
LIKE '2%' OR el1
LIKE '6%' OR el1
LIKE '9%')
73 -- on exclut les repartitions
74 AND el1
NOT LIKE '96%'
75 AND el1
NOT LIKE '97%'
76 AND el1
NOT LIKE '98%'
77 AND el3
LIKE @like_el3
80 AND imp.grpcode
LIKE @groupe
87 'REC-BUDGET' typecumul
,
89 FROM oas_balance
, oas_grplist imp
91 oas_balance.cmpcode
= 'AUF'
92 AND imp.cmpcode
= 'AUF'
94 AND period
BETWEEN 1 AND @periode
98 AND (el1
LIKE '1%' OR el1
LIKE '7%')
99 AND el3
LIKE @like_el3
102 AND imp.grpcode
LIKE @groupe
109 'REC-REEL' typecumul
,
111 FROM oas_balance
, oas_grplist imp
113 oas_balance.cmpcode
= 'AUF'
114 AND imp.cmpcode
= 'AUF'
116 AND period
BETWEEN 1 AND @periode
120 AND (el1
LIKE '1%' OR el1
LIKE '7%')
121 AND el3
LIKE @like_el3
124 AND imp.grpcode
LIKE @groupe
127 IF @exercice
= YEAR(GETDATE())
133 'PRENGAGEMENT' typecumul
,
135 FROM oas_balance
, oas_grplist imp
137 oas_balance.cmpcode
= 'AUF'
138 AND imp.cmpcode
= 'AUF'
141 AND balcode
= 'PRENGAGEMENT'
142 AND el1
NOT LIKE '4%'
143 AND el1
NOT LIKE '96%'
144 AND el1
NOT LIKE '97%'
145 AND el1
NOT LIKE '98%'
146 AND el3
LIKE @like_el3
149 AND imp.grpcode
LIKE @groupe
156 'ENGAGEMENT' typecumul
,
158 FROM oas_balance
, oas_grplist imp
160 oas_balance.cmpcode
= 'AUF'
161 AND imp.cmpcode
= 'AUF'
164 AND balcode
= 'ENGAGEMENT'
165 AND el1
NOT LIKE '4%'
166 AND el1
NOT LIKE '96%'
167 AND el1
NOT LIKE '97%'
168 AND el1
NOT LIKE '98%'
169 AND el3
LIKE @like_el3
172 AND imp.grpcode
LIKE @groupe
177 cumul.el3 projetPoste
,
180 SUM(ISNULL(budget_depenses.montant
,0)) budget_depense
,
181 SUM(ISNULL(budget_recettes.montant
,0)) budget_recette
,
182 SUM(ISNULL(reel_recettes.montant
,0)) reel_recette
,
183 SUM(ISNULL(reel_depenses.montant
,0)) reel_depense
,
184 SUM(ISNULL(engages.montant
,0)) engage
,
185 SUM(ISNULL(preengagement.montant
,0)) preengagement
192 SELECT el3
, typecumul
, montant
195 ON cumul.el3
= budget_depenses.el3
196 AND budget_depenses.typecumul
= 'DEP-BUDGET'
198 SELECT el3
, typecumul
, montant
201 ON cumul.el3
= budget_recettes.el3
202 AND budget_recettes.typecumul
= 'REC-BUDGET'
204 SELECT el3
, typecumul
, montant
207 ON cumul.el3
= reel_recettes.el3
208 AND reel_recettes.typecumul
= 'REC-REEL'
210 SELECT el3
, typecumul
, montant
213 ON cumul.el3
= reel_depenses.el3
214 AND reel_depenses.typecumul
= 'DEP-REEL'
216 SELECT el3
, typecumul
, montant
219 ON cumul.el3
= engages.el3
220 AND engages.typecumul
= 'ENGAGEMENT'
222 SELECT el3
, typecumul
, montant
225 ON cumul.el3
= preengagement.el3
226 AND preengagement.typecumul
= 'PRENGAGEMENT'
227 LEFT JOIN oas_element e
228 ON cumul.el3
= e.code
229 AND e.cmpcode
= 'AUF'
232 (@exercice
< 2014 AND LEN(cumul.el3
) = 7 AND LEFT(cumul.el3
,2) <> '95')
233 OR (@exercice
>= 2014 AND LEN(cumul.el3
) = 8 AND LEFT(cumul.el3
,1) <> 'P')
234 GROUP BY cumul.el3
, e.sname
, e.
[name]