M.JAY M.JAY - 5 months ago 16
SQL Question

Excluding from case expression

I Have got this query:

select
case when EventCategory < 0.05 Then 'NOT INCL' ELSE 'OK' END AS Under3Min
from
(
Select
Sum(case when CustomEvent = 'without Stop' then cast(EventEndDateTime - EventStartDateTime as float)*24 else 0 end) as EventCategory
FROM tDataCategory


In this query I take from the table CustomEvent the `without StopĀ“ and take the sum of this duration. And in the first select I said if EventCategory is less than 0,05 then it should not included else include.
And this gave me the right output. But I would like to exclude the "not Included" complete in the output.
How can I exclude this issue?

Answer

Add a Where condition,

select 
    case when EventCategory < 0.05 Then 'NOT INCL' ELSE 'OK' END AS Under3Min
from
(
    Select   
    Sum(case when CustomEvent = 'without Stop' then cast(EventEndDateTime - EventStartDateTime as float)*24 else 0 end) as EventCategory
    FROM tDataCategory
) x
WHERE x.EventCategory >=0.05