Database Administrators Stack Exchange is a question and answer site for database professionals who wish to improve their database skills and learn from others in the community. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

all! I want to know how wrote this code of SQL, I already trying but i get message error. I wrote two way different this SQL. See you below

  FROM tabela
 WHERE coluna IN (CASE WHEN 1 = :parametro THEN 1 WHEN 0 = :parametro THEN (2, 3) END)


  FROM tabela
 WHERE (CASE WHEN 1 = :parametro THEN coluna = 1 WHEN 0 = :parametro THEN coluna <> 1 END)

I tried to run but it get error. Please! you help to tick or fix this code.

Thank a lot.

Regards, Jeison Pereira

share|improve this question
It's nonsense. CASE WHEN can return only a scalar value - not a colletion like (10, 20). What exactly do you want to achieve? Look at funtion LNNVL maybe it does what you need. – ibre5041 Aug 26 '13 at 16:28

One option is

  FROM tabela
 WHERE  'OK' =
         CASE WHEN   1 = :parametro and coluna = 1 then 'OK'
              WHEN   0 = :parametro and coluna in (2, 3) THEN 'OK'
share|improve this answer

You can do it without a CASE

  FROM tabela
 WHERE (:parametro = 1 AND coluna = 1)
    OR (:parametro = 0 AND coluna <> 1 )
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.