Is there anyway to store the result of a case statement in a variable so that it has a fixed result that i can return at any point.
e.g.
CASE
WHEN MONTH([DATE]) = MONTH(getdate()) AND
YEAR([DATE]) = YEAR(getdate())
THEN SUM(Figure)
OVER (PARTITION BY [Name],
MONTH([DATE]))
ELSE 0
END INTO @MTD
Ideally i want to be able to return a consisted month to date value where the calculation is not affected by where clauses