-3

I have column location but i need to return this column based on value of another column below is the MYSQL SELECT QUERY:

if(block.block_id IS NOT NULL)
{
 location.location = 'BLOCKED'
}elseif(nvocc.nvocc_id is not null AND nvocc.nvocc_status = 'IN') {
  location.location = 'NVOCC'
}else {
  location.location = location.location
}

i treid with case conditon but its showing error

CASE 
     WHEN block.block_id IS NOT NULL THEN "BLOCKED"
     WHEN ((nvocc.nvocc_id IS NOT NULL) AND (nvocc.nvocc_status='IN')) THEN "NVOCC"
     ELSE location.location
END as location  

the above query returns nothing and not working please someone help me to solve this issue.

3
  • 1
    What about you look at the mySql tutorial Commented Aug 28, 2015 at 12:59
  • 3
    possible duplicate of How do write IF ELSE statement in a MySQL query Commented Aug 28, 2015 at 13:03
  • A query in MySQL starts with SELECT, not with CASE. It is entirely unclear what code you are actually running. Commented Aug 28, 2015 at 13:34

1 Answer 1

1

Try using parenthesis to clearly separate your condition block from control flow block:

CASE 
     WHEN block.block_id IS NOT NULL THEN "BLOCKED"
     WHEN ((nvocc.nvocc_id IS NOT NULL) AND (nvocc.nvocc_status='IN')) THEN "NVOCC"
     ELSE location.location
END

Try simplifying your query until it works and then progressively add conditions.

And please provide your error, it's really hard to guess.

Sign up to request clarification or add additional context in comments.

2 Comments

Query is excuted but i there is no change in output
please provide the full request, it is hard to know else.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.