MSSQL where condition with a case statement

--

Hello, I was creating reports of last year with month selection. I used a method for separate months of the year. I just presented a monthly selection on the front end. If the user selects a bigger month from now. I will point last year. If it is not, I will point this year. I connected 1 normal condition and one case condition for point the year

SELECT * FROM Sales WHERE

YEAR(createdDate) = case when MONTH(@NOW) < @month then YEAR(@NOW)-1 else YEAR(@NOW) end and
MONTH(createdDate) = @month

you can basically split these conditions with and parameter

--

--

Çağlar Can SARIKAYA
Çağlar Can SARIKAYA

No responses yet