1. Anuncie Aqui ! Entre em contato fdantas@4each.com.br

[SQL] Dynamic SQL in WHERE clause

Discussão em 'Outras Linguagens' iniciado por Stack, Outubro 3, 2024 às 14:52.

  1. Stack

    Stack Membro Participativo

    SELECT A.COL1, A.COL2, A.COL3, A.COL4
    FROM TABLE A, TABLE B
    WHERE B.COL1 = A.COL1
    AND B.COL2 = A.COL2
    AND B.COL3 - A.COL3
    AND B.COL4 = A.COL4


    Now I want to tune the SQL query, that whenever any of the Columns in Table B has field value 'ALL' the where clause will not come into picture.

    i.e. When it has a distinct value it will match with both the tables, when the field value is 'ALL' then to exclude from the where clause.

    Alternatively,

    I Need B.COL1= A.COL1 (When B.COL1 <> 'ALL')
    Else NO WHERE clause with B.Col1 = A.Col1 (When B.COL1 = 'ALL')

    Continue reading...

Compartilhe esta Página