skip to Main Content

The below query is part of a select query which I have got in my application

where 
case when o.tracking_id <> '0' then a.account_id is null
and 
o.status = 'N'

else
(

o.tracking_id = '0'
and 
o.status = 'N'

)
END

I am having hardtime to understand the below line

Can you please tell me what does this exactly mean ?

case when o.tracking_id <> '0' then a.account_id is null

2

Answers


  1. I wouldn’t use a CASE expression here but instead would use the following logic:

    WHERE
        (o.tracking_id <> '0' AND a.account_id IS NULL AND o.status = 'N')
        OR
        (o.tracking_id = '0' AND o.status = 'N')
    
    Login or Signup to reply.
  2. The condition is written somewhat clumsily. It is equivalent to this more readable expression:

    where (o.tracking_id = '0' or a.account is null)
    and o.status = 'N';
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search