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 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510
|
USE [EntrepotLP]
GO
/****** Object: StoredProcedure [dbo].[fn_Get_Data_from_Cube] Script Date: 04/02/2016 09:39:33 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER PROCEDURE [dbo].[fn_Get_Data_from_Cube]
-- Filtre sur années (séparées par des virgules)
@Years varchar(max)='none',
-- Filtre sur mois (séparés par des virgules)
@Months varchar(max)='none',
-- Filtre sur agents (séparés par des virgules)
@Agents varchar(max)='none',
-- Filtre sur entités (séparées par des virgules)
@Entites varchar(max)='none',
-- Filtre sur établissements (séparés par des virgules)
@Etablissements varchar(max)='none',
-- Choix de l'indicateur
@Indicateurs varchar(max)='RESDEL',
-- Filtre sur les références (séparées par des virgules)
@References varchar(max)='none',
-- Filtre sur les sociétés (séparées par des virgules)
@Societes varchar(max)='none',
-- Filtre sur type (séparés par des virgules)
@Types varchar(max)='none',
-- Filtre sur ui (séparés par des virgules)
@Uis varchar(max)='none',
-- 1 ère aggrégation des mesures
@Aggregation1 varchar(max)='mois',
-- 2 éme aggrégation des mesures
@Aggregation2 varchar(max)='none',
-- 3 ème aggrégation des mesures
@Aggregation3 varchar(max)='none',
-- Si douze mois glissant = 1, pour chaque mesure, il y a 12 colonnes correspondant au douzes derniers mois
@DouzeMoisGlissant tinyint = 0
AS
BEGIN
SET NOCOUNT ON;
declare @NoFilter int -- Si 1 => Pas de filtre
declare @FilterAll varchar(max) -- Critères MDX de filtre
declare @Filter varchar(max) -- Critère MDX de filtre pour chaque attribut
declare @StatementOnRows1 varchar(max) -- Sélection MDX en ligne de la première aggrégation
declare @ColonneRenvoyee1 varchar(max) -- Renommage et formattage de la 1 ère ligne
declare @StatementOnRows2 varchar(max) -- Sélection MDX en ligne de la deuxième aggrégation
declare @ColonneRenvoyee2 varchar(max) -- Renommage et formattage de la 2 ème ligne
declare @StatementOnRows3 varchar(max) -- Sélection MDX en ligne de la troisième aggrégation
declare @ColonneRenvoyee3 varchar(max) -- Renommage et formattage de la 3 ème ligne
declare @i int
declare @interval varchar(max) -- Critère d'interval de filtre MDX pour douze mois glissants
declare @mois varchar(2)
declare @annee varchar(4)
declare @colonnesMesures varchar(max) -- Colonnes de mesures
declare @Sql varchar(max) -- Requête SQL
declare @sql1 varchar(max)
DECLARE @SqlSplit varchar(8000)
declare @MdxQry varchar(max)
declare @col12MoisGlissant varchar(max) -- Sélection en MDX colonne des mois
set @NoFilter = 1
set @StatementOnRows1 = ''
set @StatementOnRows2 = ''
set @StatementOnRows3 = ''
set @ColonneRenvoyee1 = ''
set @ColonneRenvoyee2 = ''
set @ColonneRenvoyee3 = ''
-- Si douzes mois glissants, préparation de la sélection MDX en colonnes des douzes mois glissant puis instruction SQL de renommage et de formattage des champs
if @DouzeMoisGlissant = 1 begin
set @i = 1
set @colonnesMesures = ''
while @i <= 12
begin
set @mois = replace(str(cast((select month(dateadd(month,-@i + 1,getdate()))) as varchar(2)),2), space(1), '0')
set @annee = replace(str(cast((select year(dateadd(month, -@i + 1,getdate()))) as varchar(4)),4), space(1), '0')
if @i = 1 begin
set @interval = '{[Temps].[Mois].&[' + @annee + '-' + @mois + '-01T00:00:00]'
end else if @i = 12 begin
set @interval = @interval + ':[Temps].[Mois].&[' + @annee + '-' + @mois + '-01T00:00:00]}'
end
set @colonnesMesures = @colonnesMesures + '
CAST(CAST([[Temps]].[Mois Nom]].&[' + @annee + '-' + @mois + '-01T00:00:00]].[Measures]].[Ratio reussite]]] as float) as decimal(8,4)) as [Ratio Réussite ' + @mois + '],' +
'CAST(CAST([[Temps]].[Mois Nom]].&[' + @annee + '-' + @mois + '-01T00:00:00]].[Measures]].[Ratio echec]]] as float) as decimal(8,4)) as [Ratio Echec ' + @mois + '],' +
'CAST([[Temps]].[Mois Nom]].&[' + @annee + '-' + @mois + '-01T00:00:00]].[Measures]].[Ok]]] as int) as [Ok ' + @mois + '],' +
'CAST([[Temps]].[Mois Nom]].&[' + @annee + '-' + @mois + '-01T00:00:00]].[Measures]].[Ko]]] as int) as [Ko ' + @mois + '],' +
'CAST([[Temps]].[Mois Nom]].&[' + @annee + '-' + @mois + '-01T00:00:00]].[Measures]].[Nbre]]] as int) as [Nbre ' + @mois + ']'
if @i <> 12 begin
set @colonnesMesures = @colonnesMesures + ','
end
set @i = @i + 1
end
set @col12MoisGlissant = '[Temps].[Mois Nom].[Mois Nom],'
-- Si pas ddouzes mois glissants, préparation des mesures en colonnes et des renommages de celles-ci.
end else begin
set @colonnesMesures = '
CAST(CAST([[Measures]].[Ratio Reussite]]] as float) as decimal(8,4)) as [Ratio Réussite],
CAST(CAST([[Measures]].[Ratio Echec]]] as float) as decimal(8,4)) as [Ratio Echec],
CAST(CAST([[Measures]].[ok]]] as nvarchar(50)) as int) as [ok],
CAST(CAST([[Measures]].[ko]]] as nvarchar(50)) as int) as [ko],
CAST(CAST([[Measures]].[nbre]]] as nvarchar(50)) as int) as [nbre]'
set @col12MoisGlissant = ''
end
-- NB : Si un attribut est à la foix en axe de ligne et à la fois en filtre dans la clause WHERE en MDX, la requête ne fonctionne pas
-- =====> Pour filtrer, on filtre dans la clause WHERE en SQL et non dans la clause WHERE en MDX
set @FilterAll = ''
-- Filtre Année
if @Years = 'none'or @Years = '' begin
set @FilterAll = ''
end else begin
if @Aggregation1 <> 'annee' and @Aggregation2 <> 'annee' and @Aggregation3 <> 'annee' begin
set @FilterAll = [dbo].[fn_CreateFilter]('[Temps].[Année Nom]', @Years, ';')
set @NoFilter = 0
end else begin
if @Aggregation1 = 'annee' begin
set @StatementOnRows1 = [dbo].[fn_CreateFilter]('[Temps].[Année Nom]', @Years, ';')
end else if @Aggregation2 = 'annee' begin
set @StatementOnRows2 = ',' + [dbo].[fn_CreateFilter]('[Temps].[Année Nom]', @Years, ';')
end else if @Aggregation3 = 'annee' begin
set @StatementOnRows3 = ',' + [dbo].[fn_CreateFilter]('[Temps].[Année Nom]', @Years, ';')
end
end
end
-- Filtre Mois
if @Months <> 'none' and @Months <> '' begin
if @Aggregation1 <> 'mois' and @Aggregation2 <> 'mois' and @Aggregation3 <> 'mois' begin
if @NoFilter = 0 begin
set @FilterAll = @FilterAll + ', '
end
set @FilterAll = @FilterAll + [dbo].[fn_CreateFilter]('[Temps].[Mois Nom]', @Months, ';')
set @NoFilter = 0
end else begin
if @Aggregation1 = 'mois' begin
set @StatementOnRows1 = [dbo].[fn_CreateFilter]('[Temps].[Mois Nom]', @Months, ';')
end else if @Aggregation2 = 'mois' begin
set @StatementOnRows2 = ',' + [dbo].[fn_CreateFilter]('[Temps].[Mois Nom]', @Months, ';')
end else if @Aggregation3 = 'mois' begin
set @StatementOnRows3 = ',' + [dbo].[fn_CreateFilter]('[Temps].[Mois Nom]', @Months, ';')
end
end
end
-- Filtre Agent
if @Agents <> 'none' and @Agents <> '' begin
if @Aggregation1 <> 'agent' and @Aggregation2 <> 'agent' and @Aggregation3 <> 'agent' begin
if @NoFilter = 0 begin
set @FilterAll = @FilterAll + ', '
end
set @FilterAll = @FilterAll + [dbo].[fn_CreateFilter]('[Indicateur Liverperf].[Agent]', @Agents, ';')
set @NoFilter = 0
end else begin
if @Aggregation1 = 'agent' begin
set @StatementOnRows1 = [dbo].[fn_CreateFilter]('[Indicateur Liverperf].[Agent]', @Agents, ';')
end else if @Aggregation2 = 'agent' begin
set @StatementOnRows2 = ',' + [dbo].[fn_CreateFilter]('[Indicateur Liverperf].[Agent]', @Agents, ';')
end else if @Aggregation3 = 'agent' begin
set @StatementOnRows3 = ',' + [dbo].[fn_CreateFilter]('[Indicateur Liverperf].[Agent]', @Agents, ';')
end
end
end
-- Filtre Entites
if @Entites <> 'none' and @Entites <> '' begin
if @Aggregation1 <> 'entite' and @Aggregation2 <> 'entite' and @Aggregation3 <> 'entite' begin
if @NoFilter = 0 begin
set @FilterAll = @FilterAll + ', '
end
set @FilterAll = @FilterAll + [dbo].[fn_CreateFilter]('[Indicateur Liverperf].[Entite]', @Entites, ';')
set @NoFilter = 0
end else begin
if @Aggregation1 = 'entite' begin
set @StatementOnRows1 = [dbo].[fn_CreateFilter]('[Indicateur Liverperf].[Entite]', @Entites, ';')
end else if @Aggregation2 = 'entite' begin
set @StatementOnRows2 = ',' + [dbo].[fn_CreateFilter]('[Indicateur Liverperf].[Entite]', @Entites, ';')
end else if @Aggregation3 = 'entite' begin
set @StatementOnRows3 = ',' + [dbo].[fn_CreateFilter]('[Indicateur Liverperf].[Entite]', @Entites, ';')
end
end
end
-- Filtre Etablissements
if @Etablissements <> 'none' and @Etablissements <> '' begin
if @Aggregation1 <> 'etablissement' and @Aggregation2 <> 'etablissement' and @Aggregation3 <> 'etablissement' begin
if @NoFilter = 0 begin
set @FilterAll = @FilterAll + ', '
end
set @FilterAll = @FilterAll + [dbo].[fn_CreateFilter]('[Indicateur Liverperf].[Etablissement]', @Etablissements, ';')
set @NoFilter = 0
end else begin
if @Aggregation1 = 'etablissement' begin
set @StatementOnRows1 = [dbo].[fn_CreateFilter]('[Indicateur Liverperf].[Etablissement]', @Etablissements, ';')
end else if @Aggregation2 = 'etablissement' begin
set @StatementOnRows2 = ',' + [dbo].[fn_CreateFilter]('[Indicateur Liverperf].[Etablissement]', @Etablissements, ';')
end else if @Aggregation3 = 'etablissement' begin
set @StatementOnRows3 = ',' + [dbo].[fn_CreateFilter]('[Indicateur Liverperf].[Etablissement]', @Etablissements, ';')
end
end
end
-- Filtre Indicateurs
if @Indicateurs <> 'none' and @Indicateurs <> '' begin
if @NoFilter = 0 begin
set @FilterAll = @FilterAll + ', '
end
set @FilterAll = @FilterAll + [dbo].[fn_CreateFilter]('[Indicateur Liverperf].[Indicateur]', @Indicateurs, ';')
set @NoFilter = 0
end
-- Filtre References
if @References <> 'none' and @References <> '' begin
if @Aggregation1 <> 'reference' and @Aggregation2 <> 'reference' and @Aggregation3 <> 'reference' begin
if @NoFilter = 0 begin
set @FilterAll = @FilterAll + ', '
end
set @FilterAll = @FilterAll + [dbo].[fn_CreateFilter]('[Indicateur Liverperf].[Reference]', @References, ';')
set @NoFilter = 0
end else begin
if @Aggregation1 = 'reference' begin
set @StatementOnRows1 = [dbo].[fn_CreateFilter]('[Indicateur Liverperf].[Reference]', @References, ';')
end else if @Aggregation2 = 'reference' begin
set @StatementOnRows2 = ',' + [dbo].[fn_CreateFilter]('[Indicateur Liverperf].[Reference]', @References, ';')
end else if @Aggregation3 = 'reference' begin
set @StatementOnRows3 = ',' + [dbo].[fn_CreateFilter]('[Indicateur Liverperf].[Reference]', @References, ';')
end
end
end
-- Filtre Societes
if @Societes <> 'none' and @Societes <> '' begin
if @Aggregation1 <> 'societe' and @Aggregation2 <> 'societe' and @Aggregation3 <> 'societe' begin
if @NoFilter = 0 begin
set @FilterAll = @FilterAll + ', '
end
set @FilterAll = @FilterAll + [dbo].[fn_CreateFilter]('[Indicateur Liverperf].[Societe]', @Societes, ';')
set @NoFilter = 0
end else begin
if @Aggregation1 = 'societe' begin
set @StatementOnRows1 = [dbo].[fn_CreateFilter]('[Indicateur Liverperf].[Societe]', @Societes, ';')
end else if @Aggregation2 = 'societe' begin
set @StatementOnRows2 = ',' + [dbo].[fn_CreateFilter]('[Indicateur Liverperf].[Societe]', @Societes, ';')
end else if @Aggregation3 = 'societe' begin
set @StatementOnRows3 = ',' + [dbo].[fn_CreateFilter]('[Indicateur Liverperf].[Societe]', @Societes, ';')
end
end
end
-- Filtre Types
if @Types <> 'none' and @Types <> '' begin
if @Aggregation1 <> 'type' and @Aggregation2 <> 'type' and @Aggregation3 <> 'type' begin
if @NoFilter = 0 begin
set @FilterAll = @FilterAll + ', '
end
set @FilterAll = @FilterAll + [dbo].[fn_CreateFilter]('[Indicateur Liverperf].[Type]', @Types, ';')
set @NoFilter = 0
end else begin
if @Aggregation1 = 'type' begin
set @StatementOnRows1 = [dbo].[fn_CreateFilter]('[Indicateur Liverperf].[Type]', @Types, ';')
end else if @Aggregation2 = 'type' begin
set @StatementOnRows2 = ',' + [dbo].[fn_CreateFilter]('[Indicateur Liverperf].[Type]', @Types, ';')
end else if @Aggregation3 = 'type' begin
set @StatementOnRows3 = ',' + [dbo].[fn_CreateFilter]('[Indicateur Liverperf].[Type]', @Types, ';')
end
end
end
-- Filtre UIs
if @Uis <> 'none' and @Uis <> '' begin
if @Aggregation1 <> 'ui' and @Aggregation2 <> 'ui' and @Aggregation3 <> 'ui' begin
if @NoFilter = 0 begin
set @FilterAll = @FilterAll + ', '
end
set @FilterAll = @FilterAll + [dbo].[fn_CreateFilter]('[Indicateur Liverperf].[Ui]', @Uis, ';')
set @NoFilter = 0
end else begin
if @Aggregation1 = 'ui' begin
set @StatementOnRows1 = [dbo].[fn_CreateFilter]('[Indicateur Liverperf].[Ui]', @Uis, ';')
end else if @Aggregation2 = 'ui' begin
set @StatementOnRows2 = ',' + [dbo].[fn_CreateFilter]('[Indicateur Liverperf].[Ui]', @Uis, ';')
end else if @Aggregation3 = 'ui' begin
set @StatementOnRows3 = ',' + [dbo].[fn_CreateFilter]('[Indicateur Liverperf].[Ui]', @Uis, ';')
end
end
end
if @NoFilter = 1 begin
if @DouzeMoisGlissant = 1 begin
set @Filter = ' WHERE ( ' + @Interval + ') '
end else begin
set @Filter = ''
end
end else begin
if @DouzeMoisGlissant = 1 begin
set @Filter = ' WHERE ( ' + @FilterAll + ', ' + @interval + ') '
end else begin
set @Filter = ' WHERE ( ' + @FilterAll + ') '
end
end
-- Construction des sélection MDX des aggrégations et renommages et formattages des colonnes en fonction des aggrégations choisies
if @Aggregation1 = 'mois'begin
if @Months = '' or @Months = 'none' begin
SET @StatementOnRows1 = '[Temps].[Mois Nom].Members'
end
SET @ColonneRenvoyee1 = 'isnull(CAST([[Temps]].[Mois Nom]].[Mois Nom]].[MEMBER_CAPTION]]] as nvarchar(30)), ''Tous'') as [Aggregation1],'
end else if @Aggregation1 = 'agent' begin
if @Agents = '' or @Agents = 'none' begin
SET @StatementOnRows1 = '[Indicateur Liverperf].[Agent].Members'
end
SET @ColonneRenvoyee1 = 'isnull(CAST([[Indicateur Liverperf]].[Agent]].[Agent]].[MEMBER_CAPTION]]] as nvarchar(50)), ''Tous'') as [Aggregation1],'
end else if @Aggregation1 = 'etablissement' begin
if @Etablissements = '' or @Etablissements = 'none' begin
SET @StatementOnRows1 = '[Indicateur Liverperf].[Etablissement].Members'
end
SET @ColonneRenvoyee1 = 'isnull(CAST([[Indicateur Liverperf]].[Etablissement]].[Etablissement]].[MEMBER_CAPTION]]] as nvarchar(50)), ''Tous'') as [Aggregation1],'
end else if @Aggregation1 = 'reference' begin
if @References = '' or @References = 'none' begin
SET @StatementOnRows1 = '[Indicateur Liverperf].[Reference].Members'
end
SET @ColonneRenvoyee1 = 'isnull(CAST([[Indicateur Liverperf]].[Reference]].[Reference]].[MEMBER_CAPTION]]] as nvarchar(50)), ''Tous'') as [Aggregation1],'
end else if @Aggregation1 = 'societe' begin
if @Societes = '' or @Societes = 'none' begin
SET @StatementOnRows1 = '[Indicateur Liverperf].[Societe].Members'
end
SET @ColonneRenvoyee1 = 'isnull(CAST([[Indicateur Liverperf]].[Societe]].[Societe]].[MEMBER_CAPTION]]] as nvarchar(50)), ''Tous'') as [Aggregation1],'
end else if @Aggregation1 = 'type' begin
if @Types = '' or @Types = 'none' begin
SET @StatementOnRows1 = '[Indicateur Liverperf].[Type].Members'
end
SET @ColonneRenvoyee1 = 'isnull(CAST([[Indicateur Liverperf]].[Type]].[Type]].[MEMBER_CAPTION]]] as nvarchar(50)), ''Tous'') as [Aggregation1],'
end else if @Aggregation1 = 'ui' begin
if @Uis = '' or @Uis = 'none' begin
SET @StatementOnRows1 = '[Indicateur Liverperf].[Ui].Members'
end
SET @ColonneRenvoyee1 = 'isnull(CAST([[Indicateur Liverperf]].[Ui]].[Ui]].[MEMBER_CAPTION]]] as nvarchar(50)), ''Tous'') as [Aggregation1],'
end else if @Aggregation1 = 'entite' begin
if @Entites = '' or @Entites = 'none' begin
SET @StatementOnRows1 = '[Indicateur Liverperf].[Entite].Members'
end
SET @ColonneRenvoyee1 = 'isnull(CAST([[Indicateur Liverperf]].[Entite]].[Entite]].[MEMBER_CAPTION]]] as nvarchar(50)), ''Tous'') as [Aggregation1],'
end else if @Aggregation1 = 'annee' begin
if @annee = '' or @annee = 'none' begin
SET @StatementOnRows1 = '[Temps].[Année Nom].[Année Nom]'
end
SET @ColonneRenvoyee1 = 'isnull(CAST([[Temps]].[Année Nom]].[Année Nom]].[MEMBER_CAPTION]]] as nvarchar(30)), ''Tous'') as [Aggregation1],'
end
if @Aggregation2 = 'mois' begin
if @Months = '' or @Months = 'none' begin
SET @StatementOnRows2 = ',[Temps].[Mois Nom].Members'
end
SET @ColonneRenvoyee2 = 'isnull(CAST([[Temps]].[Mois Nom]].[Mois Nom]].[MEMBER_CAPTION]]] as nvarchar(30)), ''Tous'') as [Aggregation2],'
end else if @Aggregation2 = 'agent' begin
if @Agents = '' or @Agents = 'none' begin
SET @StatementOnRows2 = ',[Indicateur Liverperf].[Agent].Members'
end
SET @ColonneRenvoyee2 = 'isnull(CAST([[Indicateur Liverperf]].[Agent]].[Agent]].[MEMBER_CAPTION]]] as nvarchar(50)), ''Tous'') as [Aggregation2],'
end else if @Aggregation2 = 'etablissement' begin
if @Etablissements = '' or @Etablissements = 'none' begin
SET @StatementOnRows2 = ',[Indicateur Liverperf].[Etablissement].Members'
end
SET @ColonneRenvoyee2 = 'isnull(CAST([[Indicateur Liverperf]].[Etablissement]].[Etablissement]].[MEMBER_CAPTION]]] as nvarchar(50)), ''Tous'') as [Aggregation2],'
end else if @Aggregation2 = 'reference' begin
if @References = '' or @References = 'none' begin
SET @StatementOnRows2 = ',[Indicateur Liverperf].[Reference].Members'
end
SET @ColonneRenvoyee2 = 'isnull(CAST([[Indicateur Liverperf]].[Reference]].[Reference]].[MEMBER_CAPTION]]] as nvarchar(50)), ''Tous'') as [Aggregation2],'
end else if @Aggregation2 = 'societe' begin
if @Societes = '' or @Societes = 'none' begin
SET @StatementOnRows2 = ',[Indicateur Liverperf].[Societe].Members'
end
SET @ColonneRenvoyee2 = 'isnull(CAST([[Indicateur Liverperf]].[Societe]].[Societe]].[MEMBER_CAPTION]]] as nvarchar(50)), ''Tous'') as [Aggregation2],'
end else if @Aggregation2 = 'type' begin
if @Types = '' or @Types = 'none' begin
SET @StatementOnRows2 = ',[Indicateur Liverperf].[Type].Members'
end
SET @ColonneRenvoyee2 = 'isnull(CAST([[Indicateur Liverperf]].[Type]].[Type]].[MEMBER_CAPTION]]] as nvarchar(50)), ''Tous'') as [Aggregation2],'
end else if @Aggregation2 = 'ui' begin
if @Uis = '' or @Uis = 'none' begin
SET @StatementOnRows2 = ',[Indicateur Liverperf].[Ui].Members'
end
SET @ColonneRenvoyee2 = 'isnull(CAST([[Indicateur Liverperf]].[Ui]].[Ui]].[MEMBER_CAPTION]]] as nvarchar(50)), ''Tous'') as [Aggregation2],'
end else if @Aggregation2 = 'entite' begin
if @Entites = '' or @Entites = 'none' begin
SET @StatementOnRows2 = ',[Indicateur Liverperf].[Entite].Members'
end
SET @ColonneRenvoyee2 = 'isnull(CAST([[Indicateur Liverperf]].[Entite]].[Entite]].[MEMBER_CAPTION]]] as nvarchar(50)), ''Tous'') as [Aggregation2],'
end else if @Aggregation2 = 'annee' begin
if @annee = '' or @annee = 'none' begin
SET @StatementOnRows2 = ',[Temps].[Année Nom].Members'
end
SET @ColonneRenvoyee2 = 'isnull(CAST([[Temps]].[Année Nom]].[Année Nom]].[MEMBER_CAPTION]]] as nvarchar(30)), ''Tous'') as [Aggregation2],'
end
if @Aggregation3 = 'mois' begin
if @Months = '' or @Months = 'none' begin
SET @StatementOnRows3 = ',[Temps].[Mois Nom].Members'
end
SET @ColonneRenvoyee3 = 'isnull(CAST([[Temps]].[Mois Nom]].[Mois Nom]].[MEMBER_CAPTION]]] as nvarchar(30)), ''Tous'') as [Aggregation3],'
end else if @Aggregation3 = 'agent' begin
if @Agents = '' or @Agents = 'none' begin
SET @StatementOnRows3 = ',[Indicateur Liverperf].[Agent].Members'
end
SET @ColonneRenvoyee3 = 'isnull(CAST([[Indicateur Liverperf]].[Agent]].[Agent]].[MEMBER_CAPTION]]] as nvarchar(50)), ''Tous'') as [Aggregation3],'
end else if @Aggregation3 = 'etablissement' begin
if @Etablissements = '' or @Etablissements = 'none' begin
SET @StatementOnRows3 = ',[Indicateur Liverperf].[Etablissement].Members'
end
SET @ColonneRenvoyee3 = 'isnull(CAST([[Indicateur Liverperf]].[Etablissement]].[Etablissement]].[MEMBER_CAPTION]]] as nvarchar(50)), ''Tous'') as [Aggregation3],'
end else if @Aggregation3 = 'reference' begin
if @References = '' or @References = 'none' begin
SET @StatementOnRows3 = ',[Indicateur Liverperf].[Reference].Members'
END
SET @ColonneRenvoyee3 = 'isnull(CAST([[Indicateur Liverperf]].[Reference]].[Reference]].[MEMBER_CAPTION]]] as nvarchar(50)), ''Tous'') as [Aggregation3],'
end else if @Aggregation3 = 'societe' begin
if @Societes = '' or @Societes = 'none' begin
SET @StatementOnRows3 = ',[Indicateur Liverperf].[Societe].Members'
END
SET @ColonneRenvoyee3 = 'isnull(CAST([[Indicateur Liverperf]].[Societe]].[Societe]].[MEMBER_CAPTION]]] as nvarchar(50)), ''Tous'') as [Aggregation3],'
end else if @Aggregation3 = 'type' begin
if @Types = '' or @Types = 'none' begin
SET @StatementOnRows3 = ',[Indicateur Liverperf].[Type].Members'
end
SET @ColonneRenvoyee3 = 'isnull(CAST([[Indicateur Liverperf]].[Type]].[Type]].[MEMBER_CAPTION]]] as nvarchar(50)), ''Tous'') as [Aggregation3],'
end else if @Aggregation3 = 'ui' begin
if @Uis = '' or @Uis = 'none' begin
SET @StatementOnRows3 = ',[Indicateur Liverperf].[Ui].Members'
end
SET @ColonneRenvoyee3 = 'isnull(CAST([[Indicateur Liverperf]].[Ui]].[Ui]].[MEMBER_CAPTION]]] as nvarchar(50)), ''Tous'') as [Aggregation3],'
end else if @Aggregation3 = 'entite' begin
if @Entites = '' or @Entites = 'none' begin
SET @StatementOnRows3 = ',[Indicateur Liverperf].[Entite].Members'
end
SET @ColonneRenvoyee3 = 'isnull(CAST([[Indicateur Liverperf]].[Entite]].[Entite]].[MEMBER_CAPTION]]] as nvarchar(50)), ''Tous'') as [Aggregation3],'
end else if @Aggregation3 = 'annee' begin
if @annee = '' or @annee = 'none' begin
SET @StatementOnRows3 = ',[Temps].[Année Nom].Members'
end
SET @ColonneRenvoyee3 = 'isnull(CAST([[Temps]].[Année Nom]].[Année Nom]].[MEMBER_CAPTION]]] as nvarchar(30)), ''Tous'') as [Aggregation3],'
end
set @Sql = '
SELECT * FROM (
SELECT ' + @ColonneRenvoyee1 + ' ' +
+ @ColonneRenvoyee2 + ' ' +
+ @ColonneRenvoyee3 + ' ' +
+ @ColonnesMesures + ' ' + '
FROM OPENQUERY(CUBE,
''SELECT NON EMPTY ( ' + @StatementOnRows1 + ' ' + @StatementOnRows2 + ' ' + @StatementOnRows3 + ' ) ON ROWS,
NON EMPTY ( ' + @col12MoisGlissant + '{[Measures].[Ratio Reussite],[Measures].[Ratio Echec],[Measures].[ok],[Measures].[ko],[Measures].[nbre]} ) ON COLUMNS
FROM [CUBE LIVEPERF]
' + @Filter + ''') a
)'
set @sql1 = ''
DECLARE cursor1 CURSOR FOR
SELECT Item FROM [dbo].[decoupe_chaine](@sql, 8000)
OPEN cursor1
-- Ici je pensais qu'en découpant la chaine par paquets de 8000 caractères ça irait mais non !
FETCH NEXT FROM cursor1 INTO @SqlSplit
WHILE @@FETCH_STATUS = 0
BEGIN
set @sql1 = @sql1 + @SqlSplit
FETCH NEXT FROM cursor1 INTO @SqlSplit
END
CLOSE cursor1
DEALLOCATE cursor1
exec(@sql1)
END
GO |
Partager