I'm trying to use a select case in order to either use a where condition or not in a sql query. But it does not work and I can use some help how to solve this if possible
DECLARE @CategoryID Int
SET @CategoryID = 0
SELECT * FROM SomeTable
CASE WHEN @CategoryID = 0 THEN
ELSE
WHERE (dbo.SomeTable.ID = @CategoryID)
END
So if I pass 0 to the @CategoryID
parameter I should not filter at all, otherwise I want to filter. Can this be done?