-@year

Hi , I have a working case statement showing sales per month , I would now like to show @Year-1 . But for the life of me I can't work out what to change . Below is what I would like to achieve . Cheers Jon

DECLARE @year date

DECLARE @yearB date

SET @year = GETDATE()

SET @yearB = GETDATE()

SET @year = DATEADD(YEAR, DATEDIFF(YEAR, 0, @year), 0)

SET @yearB = DATEADD(YEAR, DATEDIFF(YEAR, 0, @yearB), 0)

Meant to change @yearB to @Year-1 to make it clearer

SET @year = DATEADD(YEAR, DATEDIFF(YEAR, 0, @year) - 1, 0)

Can't tell if that adjustment is needed for @yearB as well, but if it is, naturally add it there as well.

1 Like

Many thanks , that was easier than. I thought

1 Like