Reputation: 113
I need to use the CASE statement in the WHERE clause like:
WHERE p.resource_qry_seq = b.resource_qry_seq
AND p.resource_id = b.resource_id
AND (CASE
WHEN b.flexible_time IS NULL THEN
((b.activity_start >= p.activity_start AND b.activity_end < p.activity_end) OR
(b.activity_start > p.activity_start AND b.activity_end <= p.activity_end))
ELSE
b.activity_start > p.late_start
END)
I'm getting, 'missing right parenthesis' How to include such conditions according to a value in a column?
Upvotes: 0
Views: 88
Reputation: 520878
The predicate of a CASE
expression (i.e. what comes after THEN
) has to be a value, rather than logic. You can rephrase your WHERE
clause as follows:
WHERE
p.resource_qry_seq = b.resource_qry_seq AND
p.resource_id = b.resource_id AND
((b.flexible_time IS NULL AND
(b.activity_start >= p.activity_start AND b.activity_end < p.activity_end) OR
(b.activity_start > p.activity_start AND b.activity_end <= p.activity_end)) OR
(b.flexible_time IS NOT NULL AND b.activity_start > p.late_start))
Upvotes: 2