Variables complexes dans une procédure stockée
Bonjour,
Voilà une ligne de code
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
| ALTER PROCEDURE [dbo].[ComparaisonDePeriode](@NombrePeriodeCompare as int,@PeriodeCompare as nvarchar(25),@PeriodeFin as int,@Annee as int,@ChaineFiltre as nvarchar(255),@Titre as nvarchar(50))
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
-- Insert statements for procedure here
if @Periodefin-@NombrePeriodeCompare<0
begin
SELECT nom+' ('+CodeArticle+')' as Elt,datename(MONTH,dateoperation)+' '+cast(case when MONTH(dateoperation)>@PeriodeFin then @Annee-1 else @Annee end as nvarchar) as Periode,sum(QteGros+QteDetail/Rapport2) as V,@ChaineFiltre as ChaineFiltre,@Titre as Titre,case when MONTH(dateoperation)>@PeriodeFin then MONTH(dateoperation)-12 else MONTH(dateoperation) end as NbP from EntreeSortie inner join EntreeSortieArticle on EntreeSortie.NumBon=EntreeSortieArticle.NumBon and EntreeSortie.ClientFournisseur=EntreeSortieArticle.ClientFournisseur inner join p_article on EntreeSortieArticle.CodeArticle=p_article.Code where (EntreeSortie.ClientFournisseur='client') and ((month(dateoperation) between @Periodefin-@NombrePeriodeCompare+13 and 12) and (year(dateoperation)=@annee-1)) or ((month(dateoperation) between 1 and @Periodefin) and (year(dateoperation)=@annee)) group by nom+' ('+CodeArticle+')',datename(MONTH,dateoperation)+' '+cast(case when MONTH(dateoperation)>@PeriodeFin then @Annee-1 else @Annee end as nvarchar),case when MONTH(dateoperation)>@PeriodeFin then MONTH(dateoperation)-12 else MONTH(dateoperation) end
end
else
begin
SELECT nom+' ('+CodeArticle+')' as Elt,datename(MONTH,dateoperation)+' '+cast(@Annee as nvarchar) as Periode,sum(QteGros+QteDetail/Rapport2) as V,@ChaineFiltre as ChaineFiltre,@Titre as Titre,MONTH(dateoperation) as NbP from EntreeSortie inner join EntreeSortieArticle on EntreeSortie.NumBon=EntreeSortieArticle.NumBon and EntreeSortie.ClientFournisseur=EntreeSortieArticle.ClientFournisseur inner join p_article on EntreeSortieArticle.CodeArticle=p_article.Code where (EntreeSortie.ClientFournisseur='client') and (month(dateoperation) between @Periodefin-@NombrePeriodeCompare and @Periodefin) and (year(dateoperation)=@annee) group by nom+' ('+CodeArticle+')',datename(MONTH,dateoperation)+' '+cast(@Annee as nvarchar),MONTH(dateoperation)
end
END |
Est ce possible de créer deux variables
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13
| @bStr1 as nvarchar(225), @bStr2 as nvarchar(225)
@bstr1=SELECT nom+' ('+CodeArticle+')' as Elt,datename(MONTH,dateoperation)+' '+cast(case when MONTH(dateoperation)>@PeriodeFin then @Annee-1 else @Annee end as nvarchar) as Periode,sum(QteGros+QteDetail/Rapport2) as V,@ChaineFiltre as ChaineFiltre,@Titre as Titre,case when MONTH(dateoperation)>@PeriodeFin then MONTH(dateoperation)-12 else MONTH(dateoperation) end as NbP from EntreeSortie inner join EntreeSortieArticle on EntreeSortie.NumBon=EntreeSortieArticle.NumBon and EntreeSortie.ClientFournisseur=EntreeSortieArticle.ClientFournisseur inner join p_article on EntreeSortieArticle.CodeArticle=p_article.Code where (EntreeSortie.ClientFournisseur='client') and ((month(dateoperation) between @Periodefin-@NombrePeriodeCompare+13 and 12) and (year(dateoperation)=@annee-1)) or ((month(dateoperation) between 1 and @Periodefin) and (year(dateoperation)=@annee)) group by nom+' ('+CodeArticle+')',datename(MONTH,dateoperation)+' '+cast(case when MONTH(dateoperation)>@PeriodeFin then @Annee-1 else @Annee end as nvarchar),case when MONTH(dateoperation)>@PeriodeFin then MONTH(dateoperation)-12 else MONTH(dateoperation) end
@bStr2=SELECT nom+' ('+CodeArticle+')' as Elt,datename(MONTH,dateoperation)+' '+cast(@Annee as nvarchar) as Periode,sum(QteGros+QteDetail/Rapport2) as V,@ChaineFiltre as ChaineFiltre,@Titre as Titre,MONTH(dateoperation) as NbP from EntreeSortie inner join EntreeSortieArticle on EntreeSortie.NumBon=EntreeSortieArticle.NumBon and EntreeSortie.ClientFournisseur=EntreeSortieArticle.ClientFournisseur inner join p_article on EntreeSortieArticle.CodeArticle=p_article.Code where (EntreeSortie.ClientFournisseur='client') and (month(dateoperation) between @Periodefin-@NombrePeriodeCompare and @Periodefin) and (year(dateoperation)=@annee) group by nom+' ('+CodeArticle+')',datename(MONTH,dateoperation)+' '+cast(@Annee as nvarchar),MONTH(dateoperation)
if @Periodefin-@NombrePeriodeCompare<0
begin
@bStr1
end
else
begin
@bStr2
end |
Je m'excuse des textes longs. Je vous prie de me montrer comment revenir à la ligne dans les balises de code