Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

277
Vistas
Nested CASE statement in the WHERE clause

I am trying to use NESTED CASE statement(BOLD Below) where, based on first CASE statment, I need to verify inner where clause, else other inner where clause. Is below right approach when using nested CASE When statements?

SELECT COUNT(*)
FROM   <list of table>
WHERE  <list of conditions > 
AND    CASE  WHEN cond1 <> 1 or cond2 <>2 or cond3 <> 3
             THEN 
                WHEN ( col1,col2,col3) NOT IN (SELECT col1,col2,col3
                                               FROM   table 1,table 2
                                               WHERE  <condition1> )
                ELSE ( col1,col2,col3,col4) NOT IN (SELECT col1,col2,col3,col4
                                                    FROM   table 1,table 2
                                                    WHERE  <condition2> )
             END
over 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

Use AND and OR:

SELECT COUNT(*)
FROM   <list of table>
WHERE  <list of conditions > 
AND    (  (   ( cond1 <> 1 OR cond2 <> 2 OR cond3 <> 3 )
          AND (col1,col2,col3) NOT IN (SELECT col1,col2,col3
                                       FROM   table1
                                              INNER JOIN table2
                                              ON (<condition>)
                                       WHERE  <condition1>)
          )
       OR (   NOT ( cond1 <> 1 OR cond2 <> 2 OR cond3 <> 3 )
          AND (col1,col2,col3,col4) NOT IN (SELECT col1,col2,col3,col4
                                            FROM   table1
                                                   INNER JOIN table2
                                                   ON (<condition2>)
                                            WHERE  <condition2> )
          )
       )

Notes: Do not use legacy comma joins, use the modern ANSI join syntax.

over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda