Utilisation de la clause WHERE CASE WHEN ELSE END dans une procédure stockée
Bonjour
Toujours dans ma quête d'étudier les procédures stockées, j'ai écrit ceci
Code:
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
|
CREATE PROCEDURE [dbo].[ChiffreDeAffaire]
-- Add the parameters for the stored procedure here
@NombrePeriodeCompare as int,
@PeriodeComparee as nvarchar(25),
@PeriodeFin as int,
@Annee as int
AS
BEGIN
declare @Inc as int
set @inc=1
if @PeriodeComparee='TRIMESTRE'
begin
while @inc<=@NombrePeriodeCompare
begin
if @Periodefin-@inc<0
begin
SELECT cast(@Periodefin-@inc+5 as nvarchar)+'° TRIMESTRE '+cast(@Annee-1 as nvarchar) as Periode,'ACHAT' as Elt,sum(V) as Valeur,@Periodefin-@inc as NbPeriode,'Montant' as NomValeur,0 as Ordre from chiffre_d_affaire_achat where (case
when @Periodefin-@inc+5=1 then month(dateoperation)<=3
when @Periodefin-@inc+5=2 then month(dateoperation) between 4 and 6
when @Periodefin-@inc+5=3 then month(dateoperation) between 7 and 9
else month(dateoperation)>9 end) and (year(dateoperation)=@annee-1) group by month(dateoperation)
end
end
set @Inc=@Inc+1
end
END
GO |
A l'exécution, voilà le message d'erreur qu'il affiche
Code:
1 2
| Msg*102, Niveau*15, État*1, Procédure*ChiffreDeAffaire, Ligne*23
Syntaxe incorrecte vers '<'. |
Y a t il une manière d'utiliser la clause CASE WHEN THEN ELSE END après le WHERE?