how to remove or condition in my query

Hi Experts,

how to remove or condition in the below query:

SELECT IF(w.task_status ='TASK-NOTCOMP' AND t.success IS NULL OR (w.task_status = 'TASK-ACT-IDLE' AND t.action_status='TASK-ACT-IDLE' AND UNIX_TIMESTAMP(t.scheduled_time) < UNIX_TIMESTAMP(NOW())+600 ), 'PHYSICAL', 'LOGICAL') as output, t.workaction_id, w.task_status,w.task_id  FROM workaction as t INNER JOIN work as w ON (t.task_id=w.task_id) WHERE (t.task_id IN (423934))

the above query

if condition A OR condition B   --->PHYSICAL,LOGICAL
IF both conditons true -->PHYSICAL

Because of or condition i am unable to convert  this sql query to Hibernat hql query
is there any alternative query for this ?
how to remove or condition?

Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.



case A and B then PHYSICAL else case A then PHYSICAL,LOGICAL else case B then PHYSICAL,LOGICAL else LOGICAL end end end

Walter RitzelSenior Software EngineerCommented:
Try this:
select case 
           when (w.task_status ='TASK-NOTCOMP' AND t.success IS NULL) and (w.task_status = 'TASK-ACT-IDLE' AND t.action_status='TASK-ACT-IDLE' AND UNIX_TIMESTAMP(t.scheduled_time) < UNIX_TIMESTAMP(NOW())+600 ) then 'PHYSICAL' 
           when (w.task_status ='TASK-NOTCOMP' AND t.success IS NULL) then PHYSICAL,LOGICAL 
           when (w.task_status = 'TASK-ACT-IDLE' AND t.action_status='TASK-ACT-IDLE' AND UNIX_TIMESTAMP(t.scheduled_time) < UNIX_TIMESTAMP(NOW())+600 ) then 'PHYSICAL,LOGICAL'
           else 'LOGICAL' end  as output, t.workaction_id, w.task_status,w.task_id  FROM workaction as t INNER JOIN work as w ON (t.task_id=w.task_id) WHERE (t.task_id IN (423934))

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
srikoteshAuthor Commented:
Hi Experts,
The above query is working fine.
case A and B  true then physical
case A  true then physical ,logical  //i did not understand this point because if case A is true then phyiscal why we need to place logical as well in this line
case B true then physical,logical  else logical end

shall i do like this

case A and B true then physical
case A true then physical
case B true then physical
esle logical end.

if this is not correct
explain the scenario bit clarity.
Protecting & Securing Your Critical Data

Considering 93 percent of companies file for bankruptcy within 12 months of a disaster that blocked access to their data for 10 days or more, planning for the worst is just smart business. Learn how Acronis Backup integrates security at every stage

Walter RitzelSenior Software EngineerCommented:
The above assumes that you are delivering strings, as you have requested. If Physical and Logical are not strings, then you should explain that and we can change the query.

Your definition:
if condition A OR condition B   --->PHYSICAL,LOGICAL
IF both conditons true -->PHYSICAL
srikoteshAuthor Commented:
those are strings only

condition A OR B true PHYSICAL,LOGICAL

the above condition  to remove or condition alternative way is the below one.
can you please verify it. if this is correct or not

if condition A true -->physical
if condition B true-->physical
IF both conditons true -->PHYSICAL
else (A and B FALSE)---->LOGICAL
Walter RitzelSenior Software EngineerCommented:
No, your logic is not correct. Because the only way to get logical is if both conditions are FALSE.
The OR in your original code does not do that.
The code I have provided is correct according to your original request.

You cannot have pieces of the string returned on different logic expressions in a SQL.
Thus you need to return both values in the same case.

Use the code I have provided.
srikoteshAuthor Commented:
First time i got the hibernate hql query solution in expets exchange.

It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
MySQL Server

From novice to tech pro — start learning today.