I have a table 'Route' with Id ,Name and Active columns. If Id = 0 I want to select all the Id's where Active = true.
If Id > 0 I want to select the data for particular Id where Active = true.
I tried with following Query. But not working. (here I passed 2 for a Id value.) Can someone support me?
DECLARE @ID INT
SET @ID = 2
SELECT DISTINCT Id ,Name
FROM Route
WHERE
CASE WHEN @ID > 0
THEN Id = @ID AND Active= 1
ELSE
Active=1
END
Sample Data Attached.