Reputation: 1645
I have a boolean parameter in ssrs.
How do I write the query to achive the folowing:
boolean parameter @isMultiple (value is true or false)
the SQL Query is:
Select employee from employeeTable
WHERE
CASE @isMultiple
WHEN 'True' then employeeID in(@EmployeeIDSelected)
WHEN 'False' then EmployeeID=@EmployeeID
END
Thank you
Upvotes: 0
Views: 133
Reputation: 12005
If you still want to use CASE, you could do something like this:
Select employee from employeeTable
WHERE 1 =
(CASE @isMultiple
WHEN 'True' then (CASE WHEN employeeID in(@EmployeeIDSelected) THEN 1 END)
WHEN 'False' then (CASE WHEN EmployeeID=@EmployeeID THEN 1 END)
END)
You might want to check query plans before deciding if it was worthwhile, though.
Upvotes: 0
Reputation: 3137
You cannot use CASE
in WHERE
but you can use OR
. Try something like
SELECT employee
FROM employeeTable
WHERE (@isMultiple = 'True' AND employeeID IN (@EmployeeIDSelected))
OR (@isMultiple = 'False' AND EmployeeID = @EmployeeID)
Upvotes: 3