The query below allow me to get data from the year 2019 and 2018 :
SELECT
[DATE] = GL_DATEPIECE
[STORE] = GL_ETABLISSEMENT,
[RAYON] = GL_FAMILLENIV1,
[SALES] = SUM(CASE WHEN YEAR(GL_DATEPIECE) = 2019 THEN [GL_TOTALTTC] ELSE 0 END)
[SALES Y-] = SUM(CASE WHEN YEAR(GL_DATEPIECE) = 2018 THEN [GL_TOTALTTC] ELSE 0 END)
FROM GCLIGNEARTDIM
WHERE
GL_DATEPIECE BETWEEN '2019-11-01' AND '2019-11-02'
OR GL_DATEPIECE BETWEEN '2018-11-01' AND '2018-11-02'
GROUP BY GL_ETABLISSEMENT, GL_FAMILLENIV1, GL_DATEPIECE
I want to create a procedure to get data [SALES] for the entered date, and data for the previous year [SALES Y-]
EX : if i type in the procedure parameter : @StartDate : '2019-10-01' & @EndDate : '2019-11-01' then i should get the [SALES] data from this period.
And Data of the previous year for [Sales-1] : '2018-10-01' & '2018-11-01'