Reputation: 5819
Supose I have a table like
Id | IsActive
1 | True
2 | False
And i want to search items that are active, not active or both
I would like to have a query
declare @ActiveState bit
Select * from myTable where IsActive...
and on my where clause i would like to have something like
if(@ActiveState != null)
myTable.IsActive == @ActiveState
else
myTable.ActiveState == true || myTable.ActiveState == false
but i can't find a way to do this on the same where clause
tks
Upvotes: 0
Views: 89
Reputation: 146603
Where IsActive = IsNull(@ActiveState, IsActive)
or
Where IsActive = Coalesce(@ActiveState, IsActive)
Upvotes: 1
Reputation: 30141
WHERE myTable.IsActive = @ActiveState OR @ActiveState IS NULL
Upvotes: 1
Reputation: 308538
select * from myTable where @ActiveState is null or IsActive = @ActiveState
Upvotes: 1