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
|
CREATE PROCEDURE [dbo].[MappingMaster_ReferencesMois1](
@PremiereDate DATETIME,
@DerniereDate DATETIME,
@NumNatureDispositif int,
@ActionCorrectriceON Int
) AS
SELECT TOP 100 PERCENT REFERENCE, DureeModule
FROM TYPESDEFORMATION
WHERE ( ( @PremiereDate Is NULL ) OR -- Tu ne fais le filtre que si @PremiereDate n'est pas NULL!
( ( DateDebutFormation >= CONVERT(DATETIME, @PremiereDate, 102) ) AND
( DateFinFormation >= CONVERT(DATETIME, @PremiereDate, 102) )
)
) AND
( ( @DerniereDate Is NULL ) OR -- Tu ne fais le filtre que si @DerniereDate n'est pas NULL!
( ( DateDebutFormation <= CONVERT(DATETIME, @DerniereDate, 102) ) AND
( DateFinFormation <= CONVERT(DATETIME, @DerniereDate, 102) )
)
) AND
( ( @NumNatureDispositif Is NULL ) OR
( CodeNatureDispositif = @NumNatureDispositif )
) AND
( /* Ici tu listes tous les cas où tu n'as
pas besoin de filter sur ActionCorrectriceON... */
( @NumNatureDispositif In ( 1, 2, 5, 6 ) ) OR
/* ... et donc si tu arrives là c'est que tu as
besoin de filter sur ActionCorrectriceON */
( TYPESDEFORMATION.ActionCorrectriceON = @ActionCorrectriceON )
)
ORDER BY [N°DOMAINE], DateDebutFormation
GO
-- Exemple d'appels :
-- cet appel effectuera tous les filtres
[dbo].[MappingMaster_ReferencesMois1] '01/01/2005', '31/01/2005', 15, 0
-- cet appel n'effectuera pas le filtre sur @ActionCorrectriceON
[dbo].[MappingMaster_ReferencesMois1] '01/01/2005', '31/01/2005', 5, 0
-- cet appel n'effectuera pas le filtre sur @PremiereDate
[dbo].[MappingMaster_ReferencesMois1] NULL, '31/01/2005', 1, 0
-- cet appel n'effectuera AUCUN filtre
[dbo].[MappingMaster_ReferencesMois1] NULL, NULL, NULL, NULL |
Partager