I have the following query:
DECLARE @IsStocked bit
SELECT * FROM Products p WHERE p.LastSeen > GETDATE() - 30
This returns all Products that have been seen within the last 30 days.
My question is, I would like the p.LastSeen > GETDATE() - 30
clause to only apply when @IsStocked = true
.
This is part of a larger query, and I'd like to achieve this without using IF/ELSE statements (i.e. if @IsStocked = false
the p.LastSeen > GETDATE() - 30
section of the WHERE clause is ignored completely).
Thanks!