Reputation: 157
Hi I am doing a simple sql report and can not wrap my head around how to do this simple case statement . a parameter is either 1 or 0 for @risk. If there is a risk then return all of the records with risks > 0 if there is no risk then return all the safe records > 0
SELECT count(b.observationid), a.NumAtRisk , a.CBICode, c.Observerid, d.CBIDescription, d.CBIcatID
FROM dbo.ObservationDetails a
JOIN dbo.Observation b
ON a.ObservationID = b.ObservationID
join #Temp c
on c.Observerid = b.ObserverID
join CBI d
on a.cbiid = d.cbiID
where b.ObservationDate between @Begdate and @Enddate
-- Parameter needs to return one or the other......................
and case when
(@risk) = 1 then [a.NumAtRisk] > 0
else [a.NumSafe] > 0
end
Upvotes: 0
Views: 68
Reputation: 1269563
Something like this:
where (@risk = 1 and a.NumAtRisk > 0) or
(@risk = 0 and a.NumSafe > 0)
A case
expression is not needed.
Upvotes: 4